Make NPC follow the player around objects

Hi there,

i try to explain what i have and then, what the problem is:

I implemented the Hello Collision example (the one with the town.zip scene).
Now i can walk there and add other physic objects to it. So i added an object that follows me (for example a human that follows me). In this case the “human” is just a simple box that i added to the physics space. Now i am able to create a vector that points towards me outgoing from the box. I use this vector to accelerate the box towards my direction until it reaches me.

What if the box collides with an object within the scene? For example the thing in the middle of the “town”-scene? It just walks against the wall without trying to find a way around it. So basically the question is: Is there a best-practice-way to implement a AI that walks around objects and/or navigates through tunnels and rooms until it reaches the camera position vector? If not, give me a hint what i have to search for or tell me some mechanisms i can use for it (i read something about A-STAR, navigation meshes and so on, but don’t know what could be the easiest way to fix my problem).

First of all i try to figure out how much work it means to me and if it’s possible to make something like that. The tutorials and advanced docs are done and i understand most of the stuff and now i try to go a little bit deeper into it. What is a 3d game without an enemy or another character somewhere? So the first thing is to make it follow you. ^^

thanks!
daniel

Theres a small AI library with collision avoidance in the contribution repository, you can install it via Tools->Plugins its not yet documented though. Generally its a very common topic, just typing “game navigation” or “ai navigation / steering” to google should literally flood you with results. A* is also very common but works better if you have a tiled game area.

Yes, You are right. A* is probably the easiest for you.
It’s quite easy to impement, but I think that JMonkey already has one, using navigation meshs but I have never tried this yet.

Arf. Normen is quicker than me ;-).

I should just add that A* works on graphs. No need to have tiles as long as you have positions and links between them.
If you have, for example, a deep empty (almost) space environment, I think a graph would be better than tiles.

yeah i think norman is a bot containing all answers :wink: thanks. I try it with A*.

Arf. Normen is quicker than me ;-) .

I should just add that A* works on graphs. No need to have tiles as long as you have positions and links between them.

If you have, for example, a deep empty (almost) space environment, I think a graph would be better than tiles.

Yeah but to use A* you’d have to create a graph first if its a “random” environment, a tiled world already is a simple graph with 4 connections per node. I wouldn’t try to use A* in empty space really, maybe for an AI to evaluate a map (like a graph) and then use it accordingly, not to define the actual waypoints from Earth to Mars. Check out the collision avoidance in the library, it works with the current “line of sight” of the object which also makes more sense than you NPCs knowing that the enemy is behind that corner and that they have to pass through the whole warehouse on a complicated path to get there :wink:

Hello

The following site is really useful when developping (semi-)autonomous entities.
In your case, The “LeaderFollowing” subsection should be good (eventually adding the “obstacle avoidance” strategy ).
Remarks : There is no planning in this solution, just pure vector-based movement.

regards

@normen said: Theres a small AI library with collision avoidance in the contribution repository, you can install it via Tools->Plugins its not yet documented though. Generally its a very common topic, just typing "game navigation" or "ai navigation / steering" to google should literally flood you with results. A* is also very common but works better if you have a tiled game area.

Is there any javadoc info on what’s provided? I can’t seem to find it.

@avpeacock said: Is there any javadoc info on what's provided? I can't seem to find it.
Nope, not yet I think.

A while back I implemented the A* pathfinding for a 2d game of mine. There are open source A* algorithms on the web, but if that doesnt suit your needs, google any other pathfinding algorithim. Waypoints for pathfinding is easy on CPU but is not usually seen in modern games as far as i know. If your map is not grid based, I have seen that modern games use a system that draws out all of the walkable areas in polygons and the AI sticks to these shapes. Good luck with your game!

Navigation meshes are still used fairly commonly…