Crystal Space 3D

Introduction

celNavigationTools it's part of celtool that makes a bunch of useful operations for navigation.

You need to choose Navigator - entity with pcmesh and tracked Target - vector or other entity or map mode.

Then information is returned to celNavigationInfo or choosed variables in blxml:

• bool success - if everything is ok, entity exists, target exist etc.
• bool visible - if target is visible
• float distance - distance between navigator and target
• vector3 angle - angle between navigator and target (note it's angle between point-point in worldspace, it doesn't include direction vectors)

Simplest case : quite dumb car

• Determine track by placing nodes on the map. Name that objects for example "waypoint1" "waypoint2" etc. Usually the best way is duplicating nodes along spline or bezier.
• In every AI loop step (1/10s for example) set Navigator to car entity and target to map node named "waypoint"+waypoint_nr and check what celNavigationInfo says.
• Moving - if distance is far than car can move fast. If distance is close and speed too high then use brakes.
• Steering - for this we need to know final_angle between car direction and target position (vector-point) because celNavigationInfo::angle gives point-point angle.

Usually car_rotation.y should be mirrored BUT in CEL 1.0 camera and pcactormove, pcwheeled and pchover are mirrored already, then don't do this.

After this operation also is nice to fix angles:

if final_angle >= PI then final_angle -= 2*PI

if final_angle < PI then final_angle += 2*PI

Right side it's angle from 0 .. -PI and left 0 .. PI. Now we know where to steer:

if final_angle < -0.1 then SteerRight

else if final_angle > 0.1 then SteerLeft

else if SteerStraight

• If car will reach waypoint trigger, then increase waypoint_nr.