Crystal Space 3D
 Revision as of 22:08, 4 February 2007 (edit)m (→Introduction)← Previous diff Revision as of 22:09, 4 February 2007 (edit) (undo)m (→Introduction)Next diff → Line 11: Line 11: * ''bool visible'' - if target is visible * ''bool visible'' - if target is visible * ''float distance'' - distance between navigator and target * ''float distance'' - distance between navigator and target - * ''vector3 angle'' - angle between navigator and target (note it's angle between point-point in worldspace, it omits direction vectors) + * ''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 == == Simplest case : quite dumb car ==

## 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 to do this is making spline/bezier and automatically duplicate nodes on this.
• In every AI loop step (1/10s for example) set Navigator to car entity, and target to map node "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). Note that angle it's point-point.

Usually car_rotation.y should be mirrored BUT in CEL 1.0 camera and then 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.