New Code Same as Old?

The instructor replaced

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

With

CurrentYaw = FMath::Lerp(CurrentYaw, TargetYaw, 0.02f);
FRotator DoorRotation = GetOwner()->GetActorRotation();
DoorRotation.Yaw = CurrentYaw;
GetOwner()->SetActorRotation(DoorRotation);

I’m just wondering how these are different in the way they go about opening the door. Both compile and work.

There’s always multiple ways of doing the same thing. That said I would have written it like so

FRotator OpenDoor = GetOwner()->GetActorRotation();
OpenDoor.Yaw = FMath::Lerp(OpenDoor.Yaw, TargetYaw, 0.02);
GetOwner()->SetActorRotation(OpenDoor);
1 Like

I agree. That seems much simpler, more concise, and easier to follow.

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

Privacy & Terms