質問

I have my players on a screen and the enemies spawn fine and go toward whatever player is closest. If I add a wall however and the wall is in between the player and enemy, the enemy will stay at the wall, trying to go through it. How could I go about this to make the enemy maneuver around the wall before it gets to the wall?

役に立ちましたか?

解決

There are a multitude of different algorithms that can be used for making this kind of path-finding. Have a look at this nice example for an A* algorithm in C#.

他のヒント

You'll need some AI algorithms to help your enemies maneuver, which I will not talk about in detail here but I shall tell you where to look further. Assuming your players can only to certain locations on the map (like cells on a chessboard), the problem can be easily solved by treating the map as a graph with node and edges then trying to find a path between 2 points.

If you're lazy to read the algorithms and implement them, a very easy approach is just let the enemy "find" its path randomly: if it hits a wall, the enemy will randomly pick another direction to continue. It's sort of like a robot which turns 90 degree every time it hits a wall; it's not efficient but you'll get there.

If the players can move anywhere in the map (in other words their locations are not confined to cells), you'll need some algorithm that takes the geometry of the walls into account (sort of like a convex polygon) and find the shortest path around each object.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top