Unlike the instructor, I have the closing and opening of the door in one function.
void UOpenDoor::MoveDoor(float DeltaTime)
{
CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f);
FRotator DoorRotation = GetOwner()->GetActorRotation();
DoorRotation.Yaw = CurrentYaw;
GetOwner()->SetActorRotation(DoorRotation);
}
YawOffset variable is now responsible for turning Yaw.
private:
float CurrentYaw, InitialYaw, TargetYaw;
UPROPERTY()
AActor* ActorThatOpens;
UPROPERTY(EditAnywhere)
float YawOffset = 90.f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
TargetYaw now changes depending on the result of the check in TickComponent.
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens))
{
TargetYaw = InitialYaw + YawOffset;
}
else
{
TargetYaw = InitialYaw;
}
MoveDoor(DeltaTime);
}