How to give curve to the ball

I have this piece of code:

 Rigidbody rigidbody = ballAttachedToPlayer.transform.gameObject.GetComponent<Rigidbody>();
 rigidbody.AddForce(transform.forward * 20f, ForceMode.Impulse);

I want to do is I want to give curve to ball. Can I enlarge this rigidbody.AddForce(transform.forward * 20f, ForceMode.Impulse); line with any parameters in order to give curve to the ball?

You can simulate a curve by adding another force 90 degrees to the ball’s course, perhaps adding something like:

// which way we going?
Vector3 travel = rigidbody.velocity.normalized;

// which way is dead-aside (left in this case I think?)
Vector3 perpendicular = Quaternion.Euler( 0, 90, 0) * travel;

// add a small force that way... make it bigger to curve more
rigidbody.AddForce(perpendicular * 2f, ForceMode.Impulse);

That force acts each frame as the ball moves.

2 Likes
rigidbody.gameObject.AddComponent<ConstantForce>().force = transform.right * 5;
1 Like