Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


projectile trajectory calculations for 3D RTS games


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 25 May 2012 - 04:25 PM

In a game I am developping, which is a 3D rts, units need to be able to fire missiles, shoot bullets, and fling balls at each other.

Normally, I would not have a problem with this. You just give a projectile a initial position, starting velocity, and optionally some movement behaviour. Let the physics do their work, sit back and enjoy the show.

However, in an RTS you can't just let the user control exactly where the projectile goes, you want to let the user assign a target position(or unit) to shoot at, for one (or multiple) of his units, calculate the ideal trajectory, and the start velocity needed to achieve it.

This is the problem: the trajectory. Because in my RTS, there can be a significant height difference between certain locations on the map. There could be a mountain peak in the way for example.

One way to achieve it, might be this: doing a box collision test with the scene, along the [pi,pf] line. See what collision meshes collide with the box. From those meshes, create a 2 dimensional convex hull in the plane along [pi,pf]. Compute the bounding quadratic function of the convex hull (not sure how to do this). Then from that parabola, compute the startvelocity needed to achieve the projectile following the trajectory.

This might be a little overkill performance wise... considering you could have 500 units shooting at each other at the same time.

Is there any better way to approach (or fake) this?
If there isn't, then how would I compute a bounding parabola from a convex hull?

EDIT: actually convex hull is a pretty bad idea. I would need to find the "lowest" possible quadratic equation along the plane that doesn't collide and goes from pi to pf... no idea how to do that at all

Thanks

Edited by Xcrypt, 25 May 2012 - 04:44 PM.


Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13670

Like
0Likes
Like

Posted 25 May 2012 - 11:00 PM

The set of possible parabolic trajectories that would allow a shooter to hit a target form a one-parameter family. Each point in the terrain between them imposes a boundary on that one parameter. As you mention in your edit, you don't need to compute the convex hull. You simply need to obey the most constraining of those boundaries. If you need help figuring out the details, I might be able to help.

In any case, this only works for weapons that allow you to control the initial speed of the projectile. It might feel funny if someone is shooting a rifle at very slow speed to get a curvy bullet trajectory. Even for situations where variable speeds are more believable (e.g., a tank), I would still impose sensible ranges so you don't get something too comical (like a trajectory going up 500m into the air to hit something behind a wall 20m away, which you would get if the wall is close to the target or the shooter).

#3 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 26 May 2012 - 07:03 AM

The set of possible parabolic trajectories that would allow a shooter to hit a target form a one-parameter family. Each point in the terrain between them imposes a boundary on that one parameter. As you mention in your edit, you don't need to compute the convex hull. You simply need to obey the most constraining of those boundaries. If you need help figuring out the details, I might be able to help.


Please do :)

#4 Álvaro   Crossbones+   -  Reputation: 13670

Like
0Likes
Like

Posted 26 May 2012 - 02:29 PM

This is essentially a 2D problem, so I'll just work in 2D. The shooter is at the origin of coordinates, we are trying to hit a target at (Px,Py) while saving an obstacle at (Ox,Oy). We are going to see under what conditions the parabola

y = -a*x^2 + b*x

clears the obstacle and hits the target. I'll save you the computations, but the result is that we need a to be at least (Oy/Ox - Py/Px) / (Px - Ox). If you have multiple obstacles, compute the maximum of those expressions. You can then compute b = y/x + a*x.

EDIT: Sorry, I was a bit rushed earlier. Once you know the path that the projectile is going to follow, you need to figure out at what speed that path would obey gravity. To do that, write x as s*t and then make s = sqrt(g/(2*a)), where g is gravity as an acceleration. So the initial velocity is (s, s*b).

Try to figure the details from this outline, and if you have a hard time ask again.

Edited by alvaro, 26 May 2012 - 07:41 PM.


#5 Explodinator   Members   -  Reputation: 119

Like
0Likes
Like

Posted 28 May 2012 - 10:06 AM

If you want trajectories to look something like WC3 projectiles, I can help a bit:

Just have the linear ones move in a straight line towards the target at a constant speed in each step.

Have the ones with a trajectory do the same thing as the linear ones, but calculate the height at each step using a parabola and fitting the two points to the curve. Solve y = c(x-a)^2 + b, where c is your arc constant. Effectively, you are translating your predefined arc to fit your two points. There should be only one solution. (2 equations, 2 unknowns)

Now, to correct for the target unit moving is relatively easy. Simply recalculate the amount of X distance you have left, find the amount it has increased, and subtract that from the x value you use when calculating your y position. This will result in a gaussian-function-like curve.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS