# AddForce in the same direction as a gameObject is oriented ?

Hi guys,

I have a WheelSteering script which let me know the wheel angle and the direction (a normalized Vector2).

Using the angle value I set my car orientation like this :

``````newAngles = new Vector3(0,initRotationY - WheelSteeringCSharp.steerAngle,transform.rotation.eulerAngles.z);

newRotation = new Quaternion();
newRotation.eulerAngles = newAngles;

transform.rotation = newRotation;
``````

With the normalized Vector2 direction I compute how to move my car using the AddForce function like this :

``````if(WheelSteeringCSharp.isAccelerating){

rigidbody.AddForce(new Vector3(speed * WheelSteeringCSharp.direction.x,0, speed * WheelSteeringCSharp.direction.y));
}
``````

So my car is correctly oriented and move in the same direction of its current rotation, that’s good. But the problem is that my car speed is not always the same.

I was wondering if there is a way to orient the force in order to always set the same impulsion whatever is the direction ?

Thank you

use the transform directions. Vector3.up is always (0, 1, 0) but you can use transform.up and that will give you the up vector for that transform.

Unity Script Ref

Hi,

And what do I do with the Vector3.Up or the gameObject transform ? I’m aware about those but how to use it and solve my problem ? How to orient the force and how to always have a constant speed ?

Thank you