- Home /
Drag and throw Rigidbody2d (Angry Birds style)
How can I achieve this?
I've been googling for hours! My scene consists of some simple shapes at the moment, a sphere and some box colliders. Got the gravity how I like it.
I just need to figure out how I can take the sphere, suspend it in space, drag it and release it and watch it fly.
What have you already tried? Why didn't it work?
I've found a bunch of code snippets online that involve using variations of the 'Drag Rigidbody' script but when I run the game I clicking on the rigidbody does nothing.
So do you program or are you just looking for a cut-paste solution?
Cut and paste at this stage. This is just me playing around and learning the ropes. $$anonymous$$inda like a proof of concept.
If I were going to consider creating this for release I would delve into real coding.
Disable the rigidbody2d (or set it's value is$$anonymous$$inematic = ticked/true). When you click on the birds, save it's current position. When it is being held down on the birds, set it's position to follow your mouse/input. When you release on the birds, you can calculate the direction of where you want it to go, by taking the originalpos-currentpos. You can also calculate the power here. The shorter it is, the less powerful the shot. The more their differences, the more powerful/further it can fly. At the same time, enable the rigidbody (or it's value is$$anonymous$$inematic = unticked/false) At the same time, addforce to the birdy and it will fly "automatically" with the physics.
This is just one way to do it.