Adding a constant force... How?

Hey
I want to add a contant force to a ball.
So it holds the same speed at all times.
How?

Did you even search?

Your object must have a rigidbody component and if you don’t want gravity, uncheck it in the inspector

public class Ball : MonoBehaviour{

	// Use this for initialization
	void Start () {
		rigidbody.AddForce(forceX, forceY , forceZ );
	}

Select ball, navigate Component-Physycs and click Constant Force, thats all if I understand question :wink:

You could try this:

    function Update () {
    	rigidbody.velocity = Vector3(0, 0, 5);
    }

or

    function Update () {
    	rigidbody.velocity.z = 5;
    }

to make it constantly move in the Z direction. Hope this helps.

Your question seems a little odd, but don’t worry I got the solution.
Since you constantly want to add force you can do that in the update function (or whatever code you right in between those curly brackets will get executed)since it get called every frame. Assuming that you want to add a force forward at all times(z-axis) right this code:

public class Ball : MonoBehaviour{

    public Rigidbody rb;
    
     
     void Start(){
    
    rb = GetComponent<Rigidbody>();
    
    }
    
    
    void Update(){
    
    
    rb.AddForce(0,0,200/*I put this as and example you can tweak it to adjust your ball speed*/);
    
    }
    
    }