我有情况。我想在前进的同时顺利更改 FOV。在父类的相机设置中,我设置默认值:
FollowCamera->FieldOfView = 90.0f;
然后在向前移动功能中,我这样设置它
void AStarMotoVehicle::MoveForward(float Axis)
{
if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
{
//Angle of direction of camera on Yaw
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
FollowCamera->FieldOfView = 140.0f;
}
实际上它有效,所以当我继续前进时,FOV更改为140,但它非常粗略地工作并且立即发生。我想从 90 顺利地完成到 140。 你能帮我吗?
FInterpTo将为您制作: https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FMath/FInterpTo/index.html
每次调用"前进"时,fov 将增加到 140。 要减慢/加快转换速度,请减小/增加"互点速度"值
使用您的代码:
void AStarMotoVehicle::MoveForward(float Axis)
{
if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
{
//Angle of direction of camera on Yaw
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
// could check if World is valid
UWorld *World = GetWorld();
const float CurrentFOV = FollowCamera->FieldOfView;
const float InterpSpeed = 2.0f
FollowCamera->FieldOfView = FMath::FInterpTo(CurrentFOV,
140.0f,
World->GetTimeSeconds(),
InterpSpeed);
}