- Home /
Angry Birds hold, drag and catapult an object ...
Hi:
I want to be able to hold, drag and catapult an object from a corner of the screen to the opposite corner at an angle and speed from my drag. Download the #1 game on the Apple Store to see what I mean.
Help,
Chepe
Not only have you provided a insufficient description of what you are trying to acheive, you have shown no initiative to understand the problem, let alone solve it. We are not here to make your game, please try to refine your concept and ask a more specific question.
Your question is too broad to be answered. If you have a specific problem, feel free to ask about it.
So you would like to clone the #1 game from the AppStore, but don't know how?
Ye, I think it's like that. Not only, he also wants somebody else do the job! LOL
Answer by runevision · Jun 07, 2010 at 03:00 PM
Copying Tetrad's comment since he didn't post it as an answer...
Well you usually have some position in the world that your sling shot is in (originalPosition
). You can for example set that position on mouse down.
Then your drag will move your projectile to some other position in the world (draggedPosition
). You could set that position on mouse up.
Subtract these two vectors to get a new vector from the projectile to the sling shot:
var shootVector = originalPosition - draggedPosition;
Use the vector's direction to set the force direction, and the magnitude to set the force amount (where further away is higher force magnitude, obviously). Actually you can do that just by setting the force directly to the vector, possibly with a multiplier:
projectile.rigidbody.AddForce(shootVector * multiplier, ForceMode.Impulse);
From there's it's usually a matter of just making sure your physics properties are set up right. More info here:
http://unity3d.com/support/documentation/Manual/Physics.html
Answer by Chepe · Jun 05, 2010 at 03:46 PM
I know how to drag the object but what would be the best way to calculate the force and angle based on the position of the drag. Again Im an artist, so Im giving it my best shot. I will post my code here very soon ...
Well you usually have some position in the world that your sling shot is in. Then your drag will move your projectile to some other position in the world. Subtract these two vectors to get a new vector from the projectile to the sling shot. Use the vector's direction to set the force direction, and the magnitude to set the force amount (where further away is higher force magnitude, obviously). From there's it's usually a matter of just making sure your physics properties are set up right. $$anonymous$$ore info here: http://unity3d.com/support/documentation/$$anonymous$$anual/Physics.html
@Tetrad, he's an artist, are you trying to make his head explode? :)
Also, don't answer a question with another question/comment. Read the FAQ: http://answers.unity3d.com/faq