<strong>[RESOLVED]</strong>how to make an npc follow a player

say i use the non playing charecter model otto, so far i have been able to set up the model, bring him into the game and then animate him to walk. Whoopiee but there is a serious problem…I’m using a very NON intelligent form of AI where the NPC merely mimics the players motion…that is i update his walkDirection in the update loop based on the player characters inputs. So he only moves when the player moves. How do i get him to continously follow the player around properly ???

I don’t know JME3 very well but I know this is a common roadblock to game development, essentialy their are alot of solutions its always intelligent to keep in mind an npc might get blocked along the way wheather it be a closed door, a tree that fell in front of it, or maybe an enemy is locked up on eachother.



A common solution is to place nodes in walkable areas of the map, then have the nodes(by script or by hand) map each node to another node that are visible to eachother(also known as line of sight) and have the NPC walk towards the player when it is not stuck but when the NPC gets stuck it should switch to a mode where it follows the nodes in a successfull path way(Some precomputations will be nessecary). When a door or tree or enemy or somthing is blocking the line of sight with another node you should have your node controller tell the NPC that Node is no longer an option to walk towards. I’m not sure of the complexity of your game but thats the gists of it.



Here is an image depecticing a rendered node map where the green lines represent the path ways an NPC has the option to walk, when something is blocking the visibliy the games’ engine(in this case the source engine) will turn off that node and tell NPC’s that is not an option to walk towards. More nodes also means more computations to make a succesfull path so be carefull when adding ALOT in huge envrioments.

Does anyone know if JME3 has any node/pathway libraries that compute this kind of thing the original poster is asking for?



Anyways here is the image

https://developer.valvesoftware.com/w/images/a/a6/Ep1_c17_05_nodegraph.jpg



Source to image:Nodegraph - Valve Developer Community

The SDK even has a plugin to create these kinds of nav meshes now, yes ^^

@normen said:
The SDK even has a plugin to create these kinds of nav meshes now, yes ^^


Thanks for that great insight! May we know what it is called or will you just tease us to look for it on our own?
@shanebeastlyb said:
Thanks for that great insight! May we know what it is called or will you just tease us to look for it on our own?

I will just tease you to look for it on your own as I don't recall the name right now. "NavMesh Generator"? Anyway, its not hard to find in the list of plugins.
@normen said:
I will just tease you to look for it on your own as I don't recall the name right now. "NavMesh Generator"? Anyway, its not hard to find in the list of plugins.

hehe I'll accept that answer
@shanebeastlyb said:
I don't know JME3 very well but I know this is a common roadblock to game development, essentialy their are alot of solutions its always intelligent to keep in mind an npc might get blocked along the way wheather it be a closed door, a tree that fell in front of it, or maybe an enemy is locked up on eachother.

A common solution is to place nodes in walkable areas of the map, then have the nodes(by script or by hand) map each node to another node that are visible to eachother(also known as line of sight) and have the NPC walk towards the player when it is not stuck but when the NPC gets stuck it should switch to a mode where it follows the nodes in a successfull path way(Some precomputations will be nessecary). When a door or tree or enemy or somthing is blocking the line of sight with another node you should have your node controller tell the NPC that Node is no longer an option to walk towards. I'm not sure of the complexity of your game but thats the gists of it.

Here is an image depecticing a rendered node map where the green lines represent the path ways an NPC has the option to walk, when something is blocking the visibliy the games' engine(in this case the source engine) will turn off that node and tell NPC's that is not an option to walk towards. More nodes also means more computations to make a succesfull path so be carefull when adding ALOT in huge envrioments.
Does anyone know if JME3 has any node/pathway libraries that compute this kind of thing the original poster is asking for?

Anyways here is the image
https://developer.valvesoftware.com/w/images/a/a6/Ep1_c17_05_nodegraph.jpg

Source to image:https://developer.valvesoftware.com/wiki/Nodegraph


Hehe... thanks a lot for that...I know about the mesh based ai graph traversal and path finding...its just I wanted to implement an independent controller that could possibly handle all the AI movement on its own...I can always use different algorithms for pathing since my game is really really simple but I can't understand how to seperate the ai control from the main game update.


@normen said:
The SDK even has a plugin to create these kinds of nav meshes now, yes ^^


Hey man I'd really appreciate it if you could shed some light on this plugin since im a total n00b when it comes to jMonkey... Totally dependent on you guys for help :)

Id like to knoe as well where this plugin you speak of.

@bongmonkey said:
Hehe... thanks a lot for that...I know about the mesh based ai graph traversal and path finding...its just I wanted to implement an independent controller that could possibly handle all the AI movement on its own...I can always use different algorithms for pathing since my game is really really simple but I can't understand how to seperate the ai control from the main game update.


https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:update_loop

Also follow the links on that page to application states and custom controls...

I’m working exactly on that @ShaneBeastlyB it’s my final graduation project to write an algorithm related to pathfinding =] If you just want to to a NPC follow a player, you can do it by ignoring everything else, and setting the WalkDirecion to the player’s position. This approach can bring eventually errors, as it may go through walls if it’s not colliding, or can get stuck in some situations. For a real navigation system, you need a more complex system :confused:



I’m trying to develop a library for jME that does that. It’s a mix of the NavMesh plugin, the jMETools pathfinding from the MonkeyZone and the AI Steering library from the contributions. In the end, the goal is to move a unit or a group of units without breaking the initial formation, but it can be used ignoring formations.

@zarch said:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:update_loop

Also follow the links on that page to application states and custom controls...


Oh man thanks i got it to work using my own custom control. I simply attached all my npcs to an NPC node and then added the control to npcNode. So I can translate it from outside the main update loop :) Sweetness.