Doors that swing open and close

The way the doors were either open or shut was bugging me. So i added a way of making the doors swing open and wasn’t to hard. Thought id share the implementation here for people to use, or suggest a better way of doing it if there is one.

void UOpenDoor::OpenDoor(float DeltaTime)
{
FRotator Current = (GetOwner()->GetActorRotation());
FRotator NewRotation = FRotator(0.0f, OpenAngle, 0.0f);
AActor* Owner = GetOwner();
FVector InterpRoation;
InterpRoation = FMath::VInterpNormalRotationTo(Current.Vector(), NewRotation.Vector(), DeltaTime, RotationSpeed);
Owner->SetActorRotation(InterpRoation.Rotation());
}

As a side note, both OpenAngle and RotationSpeed have been exposed as Uproperties as having the rotation set to a magic number meant that doors at a different orientation to the initial door would open at weird angles.

Hope someone finds this of use

2 Likes

Privacy & Terms