# How to change the direction of a rigidbody without adding to its speed?

I am a newbie trying to making a soccer game with Unity3D. The ball has a rigidbody attached and is moved using AddForce.

I have added a ‘swerve’ effect to the ball by enabling the user to AddForce to the ball with the input keys for one second following each kick. For example, if the ball is kicked directly ‘up’ the screen and then the left key is held down, the ball moves to the left simulating a swerve.

This is working well, but it adds speed to the ball when I only want the input to change the ball’s direction. So if the ball is kicked directly ‘up’ the screen and the ‘up’ key is held down, the ball travels further than I want it to because speed is being added. Ideally I want there to be no effect at all in this scenario, because the direction wouldn’t be changed.

So my question is: how can I add direction only to the rigidbody without altering the speed?

Here is how I am adding swerve in FixedUpdate():

``````if (shallApplySwerve) // shallApplySwerve is true for 1 second after a kick
{
Vector3 inputV3 = new Vector3(matchInputManager.Input.x, 0, matchInputManager.Input.y); // create a Vector3 from input
Vector3 swerveForce = swerveCapability * inputV3; // swerveCapability is a float to determine how much swerve to add
}
``````

Any help would be appreciated.

Hmmm. If I understand correctly, then after you kick a ball, you want to be able to alter it’s flight with “left” and “right” keys for 1 second.

If so, then instead of making a Vector3, you can just add force to the “side” of the ball :

``````[SerializeField]
private float swerveForce; //some kind of force multiplier, for adjustments

if (shallApplySwerve) // shallApplySwerve is true for 1 second after a kick
{
rb.AddForce(rb.transform.right * matchInputManager.Input.x * swerveScale, ForceMode.Impulse);
}
``````

I’m assuming that `matchInputManager.Input.x` is just `Input.GetAxis("Horizontall")`

Well, rigidbody tries to mimic real life physic. If a force is already applied to rigidbody, then it just have some velocity in given direction (vector). In theory, to change it (to be “physically acurate”) you should use another force, but…

In unity, you can alter velocity and, for e.g. change it’s direction. So to achieve what I think you want to, you can use `rb.velocity = rb.transform.forward * rb.velocity.magnitude;` on a ball, and then you can use keys, to change only ball rotation. This way the velocity will “follow” the rotation of a ball, giving a, I hope, desired result.