x


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

more ▼

asked Jun 05 '10 at 03:28 AM

Chepe gravatar image

Chepe
10 2 2 4

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.

Jun 05 '10 at 06:29 AM _Petroz

Your question is too broad to be answered. If you have a specific problem, feel free to ask about it.

Jun 05 '10 at 08:03 AM qJake

So you would like to clone the #1 game from the AppStore, but don't know how?

Jun 05 '10 at 08:22 AM Ricardo

Ye, I think it's like that. Not only, he also wants somebody else do the job! LOL

Jun 05 '10 at 11:22 AM GODLIKE

@Petroz @SpikeX, @GODLIKE : Please keep the tone in here friendly. This is NOT a place to point fingers at any users. @Ricardo : I understand the question fine and I don't thik it's that broad. Please don't use the "too broad question" card unless absolutely necessary.

Jun 07 '10 at 02:51 PM runevision ♦♦
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Jun 07 '10 at 03:00 PM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

(comments are locked)
10|3000 characters needed characters left

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 ...

more ▼

answered Jun 05 '10 at 03:46 PM

Chepe gravatar image

Chepe
10 2 2 4

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. More info here: http://unity3d.com/support/documentation/Manual/Physics.html

Jun 05 '10 at 06:40 PM Tetrad

@Tetrad, he's an artist, are you trying to make his head explode? :)

Jun 05 '10 at 07:15 PM Cyclops

Also, don't answer a question with another question/comment. Read the FAQ: http://answers.unity3d.com/faq

Jun 05 '10 at 09:39 PM qJake
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1998
x1361
x284
x132
x81

asked: Jun 05 '10 at 03:28 AM

Seen: 7048 times

Last Updated: Oct 27 '10 at 07:19 PM