"script that updates the speed of the spacecraft"
xxxxxxxxxx
// Update the Speed of a Spacecraft
void ASpacecraft::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (bIsAccelerating)
{
CurrentSpeed = Acceleration * DeltaTime;
if (CurrentSpeed > MaxSpeed)
{
CurrentSpeed = MaxSpeed;
}
}
else
{
CurrentSpeed -= Deceleration * DeltaTime;
if (CurrentSpeed < 0.0f)
{
CurrentSpeed = 0.0f;
}
}
FVector Movement = GetActorForwardVector() * CurrentSpeed * DeltaTime;
AddActorWorldOffset(Movement);
}