More Intuitive Solution, Not Sure If Ideal However

// Called when the game starts
void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();	

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	TargetYaw = 90.f;

}


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

	CurrentYaw = GetOwner()->GetActorRotation().Yaw;
	FRotator OpenDoor;
	OpenDoor.Yaw = FMath::Lerp(CurrentYaw, InitialYaw + TargetYaw , 0.02f);

	GetOwner()->SetActorRotation(OpenDoor);
}

I found the example method in the video a little difficult to follow, but this is what I came up with when I tried it myself before watching. By initializing InitialYaw and TargetYaw in BeginPlay, and then constantly updating CurrentYaw, you are able to lerp between CurrentYaw and (InitialYaw + Target Yaw). This functions perfectly, just wondering if it’s as performant or if there is anything wrong with the solution I’m not seeing. Thank you!

Also, I am aware I can initialize TargetYaw to InitialYaw + 90.f in begin play, so it’s not calculating InitialYaw + TargetYaw every tick. I’ve already changed this in my code. Is there anything else anyone can spot about my code that might not be as performant?

This is a good solution to this. You can improve performance by adding if statement when it finished moving then it stops doing this math.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms