Sign in to follow this  

How to control enemy movement

Recommended Posts

I am using navigation mesh (triangulated) together with Bullet. In navigation mesh, I find path using A*. This gives me set of "points" inside triangles from navigation mesh. From those points, I create bezier, catmull or other interpolant.

 

The problem is, how to actually "move" NPC

 

My ideas:

1)  I calculate new position via "dt" and forward vector (or local coordinate system) via derivation in a new point. This gives me correct NPC orientation and rotation, but it kinds of "break" other logic, because I "teleport" NPC from position to position (I have constant update rate, but still... if there is some small / thin Bullet collision body, it may goes through)

 

2) Use similar approach as for player. Methods like "MoveForward", "MoveLeft", "RotateAroundUp" etc. However, in this case, I am not really sure, how to calculate order of operations from interpolant. I have a current and final position (and orientation) and I need to get serie of "move" and "rotate" operations to get to that final position.

 

3) something else?

 

What is preferred solution? And how to potentioanlly do 2). I have beem looking over net, but found different ways, how to do this based on 1) or 2), but none of them was quite descriptive.

 

Share this post


Link to post
Share on other sites
Typical approach is to just set a movement vector or target location on your NPC's character controller and let it figure out how to actually get there. The path-following code can then poll and adjust every tick. The character controller uses physics and animation systems to move so there's no tunneling and everything looks right. The character controller might also deal with local object collision avoidance (steering behaviors).

Path finding generates a path and sets movement adjustments based on the next closest point. Controller feeds physics/animation. Physics/animation does the actual movement.

The weakness of the approach is that if the physics/animation system _can't_ follow through on movement for some reason, the path finding system may not know about it and try to tell the character to move somewhere it can never go forever. There's various fixes for that situation, but it's something to just be aware of and think about during testing/implementation.

Share this post


Link to post
Share on other sites

See if you can apply some LOD (level of detail - by distance or if the object is in the oplayers view) to avoid unneeded processing.

Far away or not visible doesnt require finesse, which you want greatly increase for nearby (ssen) movement.

 

Depending on how remote you might skip any interpolation between large steps BUT be ready for the possible switchover point where more accurate positioning IS needed.

 

The enemy AI system may be doing LOS (Line of Sight) determinations which might be useful to control a LOD mechanism.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this