
[Unreal Engine] FMath::Lerp
(Ultimo aggiornamento: 25 Ottobre 2020)
FMath::Lerp esegue un’interpolazione lineare tra due valori, l’Alpha varia da 0 a 1.
Module | Core |
Header | /Engine/Source/Runtime/Core/Public/Math/UnrealMathUtility.h |
Include | #include “Math/UnrealMathUtility.h” |
Esempio
Script di esempio per la rotazione.
MioScript.h:
private: float TargetYaw = 10.f; // 360.f float InitialYaw; // 270.f float CurrentYaw;
MioScript.cpp:
// Called when the game starts void UMioScript::BeginPlay() { Super::BeginPlay(); // HERE BEGIN CODE InitialYaw = GetOwner()->GetActorRotation().Yaw; CurrentYaw = InitialYaw; TargetYaw = InitialYaw + 90.f; } // Called every frame void UMioScript::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // HERE BEGIN CODE CurrentYaw = FMath::Lerp(CurrentYaw, TargetYaw, 0.02f); FRotator DoorRotation = GetOwner()->GetActorRotation(); DoorRotation.Yaw = CurrentYaw; GetOwner()->SetActorRotation(DoorRotation); }