Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: Red on December 24, 2011, 12:44:27 PM

Title: Calculating angle & velocity to have a thrown object hit a target
Post by: Red on December 24, 2011, 12:44:27 PM
i know it seems pretty specific... and i'm trying to figure out the maths to calculate the force and angle required to make an object be thrown in an arc to land where i want it to.

yes, i am brainstorming ways that i can fudge it:
- such as firing off an object towards the target point and having the grenade follow on the XZ plane and the Y axis moving it upwards until it hits the apex (distance/2) then falling downwards... it would do the trick but it wouldn't look very pretty... also figuring out how i can calculate the rate of ascension so that it has a falloff nearing the apex and then having the same rate applied backwards to calculate the downward gravity...

yeah, i know i can easily just "create object" with physics and "apply force" but that doesn't really strike me as being able to target with relative accuracy.

hmm... is there a plan to add in some trigonometry functions? that could help (since a sin-curve would be close enough for what i have in mind.)

EDIT: i'm researching how to calculate trajectories... man, i really wish i had paid better attention in math class :lol: not sure i'll be able to crack it and if you've cracked it already, i'll be your bestest of friendsies if you'd be willing to help me nail this one.
Title: Re: Calculating angle & velocity to have a thrown object hit a target
Post by: tobbeo on December 24, 2011, 04:40:56 PM
This may or not be a good solution for your game but for the type of game I am doing it works fine.

1. Animate an object from where it's created to the point you want it to end up (with a simple MoveTo, or use iTween depending on how you want it to accelerate etc.). That gives you a straight line of motion to your target. Lets call this object "Throw" just so I can reference it. For this example, lets say it's moving down the Z axis (doesn't really matter what direction though).

2. Create another gameobject and make it a child to "Throw". Animate this object using MoveTo or iTween on its local X or Y (or both, just not the Z axis) from a good range that gives you the curve you want. Like 0 to 50 to 0.

This child object will now move in an arc to your target. If you want more control, use some simple iTween functions or acceleration math to make the speed so it's speeding up until it hits the target or whatever you want.

This is the simplest method I know of and it works great for all the uses I need it for in my game. If you need a visual example, let me know and I'll try to make one for you (though during the weeks I am way too busy at the moment so it would have to be on a weekend).
Title: Re: Calculating angle & velocity to have a thrown object hit a target
Post by: jeanfabre on December 26, 2011, 07:33:17 AM
Hi,

 I think Tobbeo is right, if you don't know or don't want to get involved in computing the real trajectory of a projectile, then animating it the easiest approach.

But, if you can crack the case with math, then it's really nice. I give you few links that will give you a head start for reference.

 http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html (http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html)

This page is excellent cause it has almost all the cases, scroll down, you'll see all sorts of usage and there formula. Easy!

 Now, adding trigonometric actions to playmaker is a good idea, I'll look into this.

Bye,

 Jean

Title: Re: Calculating angle & velocity to have a thrown object hit a target
Post by: Red on December 26, 2011, 03:05:46 PM
Thank you for the suggestions and such.

i'm currently working on getting it to do what i want it to do (since i want it to be "just right." :P)
Title: Re: Calculating angle & velocity to have a thrown object hit a target
Post by: Andrew.Lukasik on January 09, 2012, 05:30:25 AM
Thanks for that link (http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html) jeanfabre! I was looking for something like this for a long time.
Now I must only figure out how to do this rocket-science-level-math in PM :D