简单的代码:
#include "Engine/World.h"
// Called every frame
void UChairComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
TurnChair();
}
void UChairComponent::TurnChair()
{
AActor* Chair = GetOwner();
FRotator Start = Chair->GetActorForwardVector().Rotation();
FRotator End = FRotator(0.0f, 60.0f, 0.0f);
float Change = End.Yaw - Start.Yaw;
float Direction = FMath::Clamp<float>(Change, -1, 1);
//终点的Yaw值 = 方向 * 速度 * 每帧所用时间 + 开始的Yaw值
float NewRoattion = Direction * 20.0f * GetWorld()->DeltaTimeSeconds + Start.Yaw;
Chair->SetActorRelativeRotation(FRotator(0.0f, NewRoattion, 0.0f));
}