How to apply linear movement to a ball

Hi guys,
sorry for my English. What I need is easy but I’m a newbee and I don’t manage to do that. I have my ball, I have my Camera with the mouseOrbit attached pointing to my ball. So, i don’t want a force on my ball! If I press W it has to move immediatly with a costant force. What I use to know the direction of my Camera is:

public Vector3 forward;

public Vector3 right;

public Vector3 moveDirection;

float h;

float v;

forward = GameObject.Find("Main Camera").transform.TransformDirection(Vector3.forward);
forward.y = 0; 
forward = forward.normalized;
right  = new Vector3(forward.z, 0, -forward.x);
h = Input.GetAxis("Horizontal");
if (Input.GetButton("Jump")&& IsGrounded())
	    rigidbody.AddForce(Vector3.up * 2000);

So I have my Direction! I just need to move my ball with a costant velocity! Transform.traslate doesn’t work because everything starts to bounce strangly. Thank you guys!

have you tried to use different ForceMode?

rigidbody.AddForce(Vector3.up *10, ForceMode.VelocityChange);

There are three primary ways to move things in Unity:

  • Direct translation - you control the transform.position directly in your scripts.
  • Rigidbody - you primarily control your object through adding force.
  • Character controller

I don’t know the particulars of your game, but it sounds like what you might want a character controller. Here are are some references:

Character Controller

Character Controller Scripting Reference

Note there are example scripts in the reference page for CharacterController.MoveSimple and CharacterController.Move. In addition if you search this list, you will find 1000’s of pages on character controllers, many of which include scripts.

If you need to interact with the ball in a physical way (i.e. bounce, spin, etc.) then a character controller won’t work. You can play with things like drag and the physic materials to reduce the random motions of the ball.