- Home /
"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?
TRANSLATION: I want to make an Angry Birds clone. I'm asking how to duplicate the slingshot launch dynamic.
Answer by 3dDude · Jul 30, 2010 at 05:44 PM
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
I know about that script and that is not what i want. I just want it to move towards my mouse at a set speed after release.
Answer by Deikkan · Jul 31, 2010 at 03:55 PM
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.
Answer by Persona · Jul 31, 2010 at 02:22 PM
You need to use a rigidbody.velocity code:
http://unity3d.com/support/documentation/ScriptReference/Rigidbody-velocity.html
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.
Your answer
Follow this Question
Related Questions
How to properly convert mouse pos to world pos 1 Answer
newbie: drag a rigidbody with mouse 2 Answers
Drag Rigidbody 2 Answers
Checking if mouse dragged from one point to another 2 Answers
Drag Object Via Axis Handles 0 Answers