How to add force on a rigidbody in unity

Here is the official article for this

https://unity3d.com/learn/tutorials/modules/beginner/physics/addforce

in the following example, when i press the mouse button, a force will be applied toward mouse pointer.

if (Input.GetMouseButtonDown(0)) {
 Debug.Log("will add forcce here");
 Debug.Log(rb);
 rb.AddForce(new Vector3(Input.mousePosition.x, 0, Input.mousePosition.y).normalized * 1000);
 return;
 }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s