[NEED_EXPLAIN] Elevate Function

void UTankBarrel::Elevate(float RelativeSpeed)
{
// Move the barrel the right amount this frame
// Given a max elevation speed, and the frame times

// ElevationChange -> Move up or move down with MaxDegreesPerSec
auto ElevationChange = FMath::Clamp<float>(RelativeSpeed, -1, 1) * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds; // multipy deltatime for time dependent
auto RawNewElevation = RelativeRotation.Pitch + ElevationChange;
auto Elevation = FMath::Clamp<float>(RawNewElevation, MinElevationDegrees, MaxElevationDegrees);
SetRelativeRotation(FRotator(Elevation, 0, 0));

}

So this is Ben’s code, and in the TankAimingComponent we pass in this function the DeltaRotator.Pitch, which in my understanding means how many degree the turret has to change ( up/down depends on the negative or positive number), called RelativeSpeed in this function precisely.
But comes to this function code, when we clamp the Relavetive Speed to -1 or 1. So in the end, the ElevationChange just have the info to come up or come down… How come can it be go up the desired rotation we need ( BUT I see it worked, so please explain for me :frowning: )
Thank you!!

UP :frowning:
Please help me soonn :frowning:

we get desire rotation because it check in every frame

Privacy & Terms