Skip to main content
GameDev.net gamedev.net
🔒 Locked

Parabolic shooting enemy? 2-D game

Started by Sivak Sep 14, 2010 at 12:56 PM 2 replies 2.6k views
Original Post
Sivak
Sivak
Here's one I was curious about an implementation.

Say you have the player and then a shot, but I want the shot to move in a parabola sort of way.

I am thinking that one would take the X/Y position of the shot, and then the X position of the player and just make the Y position by equal to that of the shot so we have those as the same and then just have some X difference, rather than trying to plot where the player would be along the parabola.

I'd like the shots to move at an equal speed, regardless of how far away the player is, although maybe a fixed speed wouldn't be bad either.

I can play with it though. Just wondering where to start. Thanks.

The parabolic shot would also move down and then up.
Sivak
taby
taby
Are you at all familiar with Newtonian gravitation?

It automatically creates parabolic paths for slow-moving objects (like missiles).
Nypyren
Nypyren
Quote:
Original post by Sivak
The parabolic shot would also move down and then up.


Down and then up? This implies that your shots are not affected by gravity alone? Or perhaps your game is top-down instead?

Generally speaking, you just need to apply a constant acceleration (same magnitude and direction), and the object will follow *some* kind of parabolic path.

In physics class, they generally use parametric continuous functions like:

x(t) = x0 + v0*t + a0*t*t
where 'x' is the position as a 2D or 3D vector, v is velocity vector, and a is acceleration vector.

In games, the common approach is to approximate the function in piecewise fashion:

initialize{  a = { 0, -9.8 }  v = { cos(launchAngle)*power, sin(launchAngle)*power }  x = launchPosition}each frame{  v = v + a * timestep // example: timestep = 0.016 for a 60 fps game.  x = x + v * timestep  // this is one of the simplest ways to integrate position  // there are also some more complicated ways that more   // accurately approximate a continuous function.}
Sivak
Sivak
No, no gravity here. We don't need any fancy-shmancy gravity in this simplistic world.

I'm thinking that cause it's parabolic, it would move at a constant X speed and only its Y position would change to just do the parabola appearance.

I'll look into what you proposed, thanks. It doesn't seem too bad...

If worse comes to worst, I'll just used aimed shots. Not as fancy, but would get the job done. Heh.
Sivak

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.