Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to implement parabolic path for projectiles

Author
Message
JORGEMAL
14
Years of Service
User Offline
Joined: 2nd Aug 2009
Location:
Posted: 24th May 2013 19:02
I wonder if this question can be asked here.

I am planning to write a game in which there will be linear and parabolic shooting of projectiles. Linear shootings will have a slope, meaning that they will not necessarily be horizontal. I have thought about using linear and quadratic functions but I see that I would need to "save" every function while they are still being drawn on the screen. I guess this is not a good choice because a user can shoot too many times which implies to "save" too many functions.

I will very much appreciate any comment.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 24th May 2013 19:22
Actually your shootings should to be affected by some kind of gravity. Is it a side action game? If this is your case then the physics laws is your friend
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th May 2013 22:37
you have only to directions of forces.
the one is your shot and the other is your gravity.
looks like this:

shot to right
dx1=0.01
dy1=0.00

falling down
dx2=0.000
dy2=0.001

x=x+dx1+dx2
y=y+dy1+dy2

dependent on the frame timestep
if you want move 1 unit in 60 frames=1 second
it is speed*(1.0/60.0)
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 25th May 2013 02:04
You might be able to do it like this:


[untested, might not work out-of-the-box]

Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2013 04:47 Edited at: 25th May 2013 06:27
Well the basic formula for a parabola is: ax^2 + bx + c

And then you have this:
x = v*cos(a)*t
y = v*sin(a)*t - ½gt²


The beauty with using time (t) in the equation is that it makes it easy to determine where your object is at any given moment. You just have to solve for T.
The equations are in my DB particle tutorial.


Demo


"You're all wrong. You're all idiots." ~Fluffy Rabbit
Jeku
Moderator
20
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 13th Apr 2014 00:22
I know this is an old thread, but you really saved me with that code example, Phaelax. Thanks

Senior Developer - CBS Interactive Music Group

Login to post a reply

Server time is: 2024-03-28 13:47:33
Your offset time is: 2024-03-28 13:47:33