Search code examples
c++game-physicsunreal-engine4timedelta

Unreal C++ Controller Input: Yaw Rotation


I'm setting my game character camera via c++, and I came across this, and even though it works, I don't understand why the code uses DeltaTime. What is the function of GetDeltaSeconds actually doing?

void AWizardCharater::LookX(float Value)  
{   
    AddControllerYawInput(Sensitivity * Value * GetWorld()->GetDeltaSeconds());  
}  

Here is the api ref : https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/APawn/AddControllerYawInput/index.html

Thanks


Solution

  • Using delta time, multiplied by some sensitivity value, is a standard method used throughout games to provide a consistent movement rate, independent of framerate.

    Consider the following code, without using delta time:

    AddControllerYawInput(1);  
    

    If you had a framerate of 10 FPS then you'd be doing 10 degrees per second. If the framerate increases to 100 FPS, you'd be doing 100 degrees per second.

    Using delta time makes the movement consistent regardless of framerate, as the time between frames decreases with faster framerate, slowing down the movement.