CEL AI Navigation
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, 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 omits 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.
- Make in your level loader creating trigger for every node.
- 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.
final_angle = celNavigationInfo::angle.y - car_rotation.y
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.