# Calculating speed and constant speed in case of AddRelativeForce ()

Hi everyone,

I have faced a problem related to RigidBody.AddRelativeForce(). I have read tons of answers concerning how to deal with Rigid Body.AddRelativeForce() but still can’t figure out my problem.

My target is to move the spaceship in space and most important is to control the velocity of forward/reverse movement and both vertical and horizontal strafe. Velocity of XYZ movement will be displayed via GUI elements. What’s more, I set certain maximum velocity limits which are different for X, Y and Z.

Well, speaking about my code, I decided to control velocity for X, Y and Z separately, but code is similar except parameters of max velocity limit:

``````if(rigObject.transform.InverseTransformDirection(rigObject.velocity).z < shipVelocities.MaxForwardVelocity){
accelearationForce += (power * Time.fixedDeltaTime * shipVelocities.AccelarationSpeed);
currentZAxisVelocity = accelearationForce;
}
if (rigObject.transform.InverseTransformDirection(rigObject.velocity).z >= shipVelocities.MaxForwardVelocity)
{
currentZAxisVelocity = currentZAxisVelocity;
if (accelearationForce != 0f) accelearationForce = 0f;
}

...

``````

There is 2 problems:
currentZAxisVelocity is not equel to rigObject.transform.InverseTransformDirection(rigObject.velocity).z, because my rigidbody have Mass as 5 and Drag as 0.1. Is it possible to calculate real velocity knowing force applied to object, Mass and Drag?

And second question is that RigidBody is still accelerating, according my code, and I understand that it should be, but my purpose is constant speed and how doing it?