"Launch" a rigidbody

Hello all,

I have been using unity for 6 days (And loving it so far)

So I want to know how to launch a rigidbody using the mouse. For example: There is a rigidbody just sitting there, I want to click on that rigidbody and drag. When i drag, the rigidbody does not follow, instead, a line connects my rigidbody to my mouse. When i release the mouse button, the rigidbody launches towards the mouse at a set speed.

So how would I do this?

if you have the standard assets imported then you can use the rigidbody dragger script. it wont do what you want but it will be close to what you want

What you could do is when you click on the rigidbody, record the transform.position of the GameObject. When you release the mouse button, record the mouse position using Camera.ScreenToWorldPoint and passing Input.mousePosition to it. You can then calculate the angle between the two points using Vector3.Angle and pass that angle to rigidbody.AddForce.

Hope this helps.

You need to use a rigidbody.velocity code:


That may solve your problem for speed. As for getting it to move toward the mouse, if you're in first person mode then set up a script with your Camera as a Target and have it move towards it.