Advertisement

Paths using waypoints

Started by July 01, 2002 10:22 PM
2 comments, last by randylw2 22 years, 4 months ago
If I have a predefined path using waypoints, it''s simple enough to just move from one point to the other. But I want the object to curve smoothly if turning. To me, the simplest way to do this, is to have a starting point, control point, and end point. But how do you calculate a smooth curve from the starting point to the end point using the control point to define how much to curve - in other words, the path curves from start point to end point passing through the control point which is somewhere in between them. If the control point is directly between the two points, then it would be a straight line. But if it''s offset some, then it should curve. Hope this makes sense
I''d suggest using Catmull Rom splines to generate a point just in front of the agent, that the agent walks towards, updating the point every AI tick.
For an introduction to Catmull Rom splines see http://www.mvps.org/directx/articles/catmull/
They are computationally fast, require four control points and the points generated will pass through the control points exactly. The splines take an x position between the centre control points and produce a y value. Because of this you would have to rotate your control points so that the centre control points were along the x-axis, this would be a simple translation to the origin (so the point you were trying to generate was at the origin), rotation so that p1 -> p2 was along the positive x axis, generation of the point on the spline, and reverse rotation and translation on that point.

This is a little convoluted, but the first thing that popped into my head :-)

Mike
Advertisement
Yep, this problem has been answered many times over in the Maths/Physics forum. If you want to move along the curve at a constant speed, you''ll need to reparameterise the curve, as using the standard curve parameter as time makes your object slow down in curves. The method to do this is in the archives of the M/P forum, or you can find it in most decent Calculus & Analytic Geometry texts.

Cheers,

Timkin
quote: Original post by randylw2
If I have a predefined path using waypoints, it''s simple enough to just move from one point to the other. But I want the object to curve smoothly if turning. To me, the simplest way to do this, is to have a starting point, control point, and end point. But how do you calculate a smooth curve from the starting point to the end point using the control point to define how much to curve - in other words, the path curves from start point to end point passing through the control point which is somewhere in between them. If the control point is directly between the two points, then it would be a straight line. But if it''s offset some, then it should curve. Hope this makes sense




Another way one might do this is to simply tweak your object''s orientation a tiny bit as it moves along the path, whenever you do its movement updates (which I presume will be relatively quickly, such as every other frame).

This is really pretty easy and works well so long as you have relatively frequent updates of position. At a given waypoint, the object figures out the difference between its current heading and the direction of the destination point. You then divide that angle (say, 30 degrees) by however many updates you expect it to take to get there (say, 30 frames/second and the distance is 5 seconds long, which means 150 updates). That means every frame the object moves it also alters its orientation by 30/150 or .2 degrees per frame. It''ll look very smooth--perhaps too smooth if you''re going for a really "organic" look. If that''s the case, randomize the amount a bit, or have it be less in the beginning and more towards the end (at first the object is fixed on something interesting, then as it nears its goal it focuses on that).

Hope that works for you...




Ferretman

ferretman@gameai.com
www.gameai.com
From the High, Cold, Snowy Mountains of Colorado

Ferretman
ferretman@gameai.com
From the High Mountains of Colorado
GameAI.Com

This topic is closed to new replies.

Advertisement