BuildingEscape Lerp using UE built in ease function

Example as to use the ease Function to interpolate smoothly on a curve.
Documentation: https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FMath/InterpEaseOut/index.html

Headerfile:

private:
	float Alpha = 0.f;

TickComponent Function:

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	FRotator rotator = GetOwner()->GetActorRotation();	

	if (Alpha < 1.f)
	{
		//Calculate the next alpha value using delta time stretch the time out by factor two => Time * 0.5
		Alpha += DeltaTime * 0.5f;
		//Make sure alpha never is bigger as 1, which will give a perfect 90 degree angle at the end
		Alpha = FMath::Min(Alpha, 1.f);
		//Get the Actor Rotator
		FRotator rotator = GetOwner()->GetActorRotation();
		//Use the ease function to slowly interpolate towards the end
		rotator.Yaw = FMath::InterpEaseOut(0.f, 90.f, Alpha, 2.f);
		//Set the new rotation on the actor.
		GetOwner()->SetActorRotation(rotator);	
	}
}

IMHO:
The usage of TargetValue and Alpha is a bit weird in the lesson. TargetValue should not change over time. The alpha value should be changed to blend from Source to Target Value. Either use a custom curve or a built in curve function (like EaseOut in this example) to introduce a smoothing curve to the blend.

Ease functions overview: https://easings.net/

1 Like

Interesting read!

Privacy & Terms