Advertisement

Movement on a set path

Started by February 10, 2008 09:27 AM
4 comments, last by Timkin 16 years, 9 months ago
Hello, if i have a set path, and i want to move between the points on the set path, how would i go about doing this with rotations, at the moment my character moves forward when he gets to one point, he turns to face another and then moves forward again. I've tried a system which basically rotates the character a little in the Y until he faces the next point, however this causes the problem that when two points are close together my character can continually rotate around one point and never reach it, this is a pretty bad side affect which i would like to resolve, it doesnt need to be fancy it just needs to work :P This is 2D movement. :)
You're solving a piecewise path-following problem and presently your solution is piecewise (i.e., follow a whole path, then match the constraints for the next path and follow that, then the next and so on...)

One solution is to start tracking to the next waypoint before your character reaches the current waypoint. This switch occurs at a small distance before the current waypoint and the path the character moves along 'cuts the corner' at the current waypoint. You can compute the incremental rotations needed to align the character onto the next track segment (line between waypoints) while it is also moving forward fairly easily (use quaternions and SLERP).

As an alternative, you can have the character pass through the current waypoint (and continue moving forward with constant speed) before it starts rotating toward the next waypoint.

The final option is to compute an arc that leaves the current track, passes through the waypoint and rejoins the next track and have the character follow that.

If you need more details please holler.
Advertisement
hmm, the SLERP method sounds good, do i have to use quaternions because at the moment im using 4x4 matrices and i dont fancy changing, if not, is there an alternative to this using matrices?

I assume the interpolation is a formula (function) you plug in you'r position and it will give you the next position along which you can then face, with the next position being just a little further along?? Am i right here or completely wrong
Check this link for a basic introduction to geomtetric slerp (as opposed to quaternion SLERP).


As for your 'cutting the corner' algorithm... consider the following diagram


The two lines represent the path segments to follow. The red arc is the path along which we want to follow to cut the corner.

Φ is the angular change we require
d: free paramter
r = d*sin(Φ/2) : radius of curvature of arc
l = r*Φ : length of arc to traverse

If we choose dΦ/dt then quite simply dl/dt = r*dΦ/dt

If the time step is Δt then
Δl = (dl/dt)*Δt = r*(dΦ/dt)Δt

You could simply choose
ΔΦ = (dΦ/dt)Δt
but this would give undesirable numerical errors. Hence use SLERP to determine ΔΦ and then use
Δl = r*ΔΦ
as a first order approximation to the distance along the arc to step. If you find this gives inacceptable errors with respect to the final position on the new path segment, then you can use a second order approximation, or correct for the discretisation caused by Δt. Ask for help if you need this and you're not sure how to proceed.

Cheers,

Timkin
Thanks for the info, the link and the description, im going to try this out when i get some more free time, i'll let you know how it goes :)

one quesstion though i find it hard to see why this method might produce numerical errors?
The increment Δl is a distance to step along the arc. However, in implementation you will step along a straight line that is (typically) tangent to the arc at the current point. There are a variety of ways to correct for this, but none of them are worth pursuing unless you specifically notice problems (i.e., the numeric errors may be within tolerable levels given your general movement discretisations).

This topic is closed to new replies.

Advertisement