Need help with 3D parabolic paths

Started by
8 comments, last by Hawkblood 11 years ago

I am building a space sim and I'm having problems with my ship not smoothly transitioning between waypoints (or sometimes missing them entirely). The code I have been writing and re-writing and re-writing (many times) has yielded the same results. I have "TurnTo" code so that my ship will look at the waypoint it has targeted. I can accelerate and decelerate if it's a straight shot with 1 waypoint. The problem comes when I have more than one. I have been using simple linear vector math to accomplish these futile efforts.

Now I would like to try an approach I didn't want: Parabolic paths between my waypoints. Essentially, I am discarding any notion of laws of motion like momentum for a "fixed" path. I hope I'm explaining it correctly.....

Basically I want each of my waypoints to be the "axis of symmetry" of a parabolic equation. Of course, this needs to be 3D. I'm not sure where to start with this, so any help would be appreciated.

Advertisement
Have you looked into steering behaviors?

You have just discovered that kinematics solutions are hard. It is a lesson that everyone gets to learn eventually. We still use IK and FK solutions in games, but they are resource-intensive and sometimes produce interesting results.

When you use physics for important gameplay parts,

"> the simulators tend to break in subtle and not-so-subtle ways.

The other option is... CHEAT.

When you need to follow a known path, just build the path and slide along it.

It's not a matter of not knowing "how" to turn, move, or avoid. It has to do with the HIGH SPEEDS involved. These ships are moving at such high speeds (nearing speed of light with the appropriate time-dilation effect), that any method that leaves timing to chance (or processor speed) will result in inconsistent results. Sure, the lower "maneuvering speeds" will be done with normal collision detection and avoidance, but I am traveling between planets at near SOL. The ship will either overshoot the waypoint or undershoot and slow down too early. Believe me, I've done my due diligence on trying......

I've been brain storming and I think instead of a parabola, I need a circular path. Here is an illustration of what I am trying to do:

[attachment=14621:Untitled.png]

The "ship" will be traveling to WP2.

It needs to avoid something, so it has pre-calculated a way around it and assigned WP1.

At some predetermined point in space "tangent A" on its way to WP1, it will begin its "curved path".

It will continue on this path until it reaches "tangent B" where it will continue on to WP2.

I hope this clears up any confusion about what I need help on....

any method that leaves timing to chance (or processor speed) will result in inconsistent results. Sure, the lower "maneuvering speeds" will be done with normal collision detection and avoidance, but I am traveling between planets at near SOL. The ship will either overshoot the waypoint or undershoot and slow down too early. Believe me, I've done my due diligence on trying......

Yes, that is the problem with any physics-based solution. Your physics system provides functions for turning and such. But because you cannot control all of the input, you cannot guarantee consistent results across the entire range.

So cheat.

You already have your spline figured out:

The "ship" will be traveling to WP2.
It needs to avoid something, so it has pre-calculated a way around it and assigned WP1.
At some predetermined point in space "tangent A" on its way to WP1, it will begin its "curved path".
It will continue on this path until it reaches "tangent B" where it will continue on to WP2.

Build the spline and follow along the path.

If something changes along the way rebuild your spline and continue.

A spline sounds intriguing. How would I go about creating one? Did some quick googling, and have no idea where to start......

I think if your moving at light speed you would have to stop traveling at half way to your target or you would crash into it. Moving at light speed means you can't just stop on a dime. Everyone on board would die.

2 words: "inertial dampeners". And no, I'm not wanting it to "stop on a dime". The solar system is a vast expanse. If the player was subjected to any conventional speeds for going between even the relatively short distances between planets, he would quit the game before he got to the first planet. Interstellar travel would take impossibly long times too. Therefore, I use "near light speed" for interplanetary travel and "faster than light speed" for interstellar travel. The NLS presents an interesting phenomenon of time dilation. The closer you get to SOL, the slower your perception of time becomes. So an outside observer could "see" you travel NLS from one planet to another and take, say 20 minutes, but you would think it only took 2 minutes. This effect is achieved by simply causing the player's ship to "go faster" than it actually is and advancing the game's clock at that same amount...... My scale is "actual" where 1 unit is 1 meter. Yes, there IS a problem with using floating point values with scales that large. I had to make a new vector storage class to accommodate it.

A spline sounds intriguing. How would I go about creating one? Did some quick googling, and have no idea where to start......


A spline is one one of the most basic elements of computer animation. The topic sometimes shows up in the For Beginners forum.

A spline is a smooth curve that is defined by a series of points, called knots or control points.

There are many kinds of splines. The most programmer-friendly type of spline is the Hermite spline family; they can be easily calculated by multiplying a matrix that defines the properties of the spline with a matrix that defines the control points, multiplying the result by a quadratic of the distance through the curve, and multiplying the result by a constant. Once you write the code you can just change swap out 16 numbers to generate any cubic Hermite spline.

Inside the Hermite spline family, the Catmull-Rom spline is especially nice for computer graphics because it has continuous smooth motion when two splines are placed next to each other. In other words, you can travel along a whole bunch of Catmull-Rom splines along a long and twisty path, and it will look good.

A few seconds on Google shows this example, which seems to cover it pretty well.

So if I am reading this right D3DXVec3CatmullRom(...) will need 4 known points in space. I can use the "tangent" points as my control points and I have to come up with the two in the middle, presumably along the curve of the sphere..... That doesn't sound too hard. I wondered what D3DXVec3CatmullRom was when I saw it in http://msdn.microsoft.com/en-us/library/windows/desktop/bb205506(v=vs.85).aspx but as you know, Microsoft is not very good with explaining anything.

So now I need to get those four vectors...... If I have anymore problems I'll post them here. Thank you for your help.

This topic is closed to new replies.

Advertisement