Move enemy only touching border
I want one of my enemy moves only at borders of surrounded area. My enemy must touch any side of border and continuously move around its limit. Surrounded area is completely dynamic as per main player take its movement.
Following image give you more idea regarding this. I have to move on dotted path and path is dynamic. I need some suggestion about this type of implementation.
Answer by dhore · Dec 13, 2015 at 02:45 AM
I'm not sure how familiar you are with AI pathfinding techniques ...but you could make a script that will generate a series of path nodes (depending on how your walls are generated you could use them to generate nodes in front of them?) and then just use an algorithm like A* to path around the nodes to the desired locations.
Thanks @dhore, for your response. $$anonymous$$y area get filled based on grid. So as cells are get filled by player movement as new path is generated for enemy.
So how to detect enemy path in this kind of situation?
Well you'd have a Node $$anonymous$$anager class which would keep track of all the pathing nodes - and the pathing nodes themselves would have data like their neighbouring nodes that you can traverse to (used for A* implementation). Then as your map/grid updates and changes it will need to be updating/generating new paths and adding new nodes to the manager class and possibly deleting nodes if you close sections too. Then as long as your enemy doesn't get cut off in any way on the grid he should still be able to use A* pathfinding like normal, it would just be on a constantly changing and evolving node grid.
$$anonymous$$y plane is completely divided in grids. As player moves filling those grid cells. So how to detect corner cells to draw path for edge monster (enemy)?
Thanks @dhore, now I have to implement this. Then after get back to you. Do you have any way through which I can travel node to node? Right now in my code, enemy take small pause at every node, not moving smoothly to node per node.
I hope you understand my this question. If you have any better way to solve this then please suggest me :)
As I mentioned in my original answer, I'd suggest using A*. If you don't know what A* is (pronounced "A star"), it's one of the most optimized pathfinding algorithms that is very commonly used for game AI pathfinding. If I had a link to a good tutorial then I'd definitely give it to you, but unfortunately I don't since I learnt it at Uni .... so I guess you're going to have to google for a tutorial yourself...
So from what I understand you are already using some sort of algorithm for the AI to calculate which node they should go to next to be able to get closer to the player. What A* does is when you give it a node to go to it'll calculate a list of nodes that you need to traverse (in order) to get to the destination node, and then you just loop through the list until you get there.
Here in my case, I don't need A* because I don't want to select a path. I just need to traverse around available nodes. I don't want to catch enemy but I just want to move enemy by touching border.
$$anonymous$$y available node list is continuously updated based on your above suggestion. Now I just want smooth code to travel node to node.
Sorry, but I can't really give you any code to help as I don't know the structure of your pathing system. But pretty much just while the AI is moving from one node to the next, start calculating where they should go if they were at the destination node already, therefore when they get there they already know the next move.
Okay thanks for your help. Now let me implement this after that I will get back to you.