catch and throw rigidbody with mouse

Hi,
I have a ball, as a rigidbody, using gravity to bounce off the ground the way balls do in real life. So far so good. I want to “catch” the ball (ie, stop it moving) when clicked with the mouse, and then be able to “throw” the ball with the mouse, ie, the ball will travel in the direction the mouse is swiped once the mouse button is released, and still be subject to gravity. In other words, I want to imitate real life catching and throwing a ball, with the mouse acting as somebody’s hand.

I’ve tried lots of different techniques, but am at a loss as to where to start. I assume I should use AddForce, but how do I stop it from moving once the mouse is clicked, and how do I get the direction the mouse has moved in before letting go of the mouse button?

Any help most appreciated.

EN

  1. Try toggling isKinematic. http://unity3d.com/support/documentation/ScriptReference/Rigidbody-isKinematic.html

  2. Very simple solutions:

http://unity3d.com/support/documentation/ScriptReference/EventType.MouseDrag.html

or

“Mouse X and Mouse Y are mapped to the delta of mouse movement.”
(http://unity3d.com/support/documentation/Manual/Input.html)

in reference to:

http://unity3d.com/support/documentation/ScriptReference/Input.GetAxis.html

Thanks NPSF3000, that should give me plenty to go on with. Thanks again.
EN