What you are referencing to is a path finder. While I've never successfully made one myself, I do know some articles that can explain the process. Like this one http://www.cokeandcode.com/main/tutorials/path-finding/
It is much easier if you are using a grid, but if you aren't, then you are in for a long ride.
enemy AI which would go through a maze and find the player
Root / Programming Questions / [.]
ChaseCZCreated:
What you are referencing to is a path finder. While I've never successfully made one myself, I do know some articles that can explain the process. Like this one http://www.cokeandcode.com/main/tutorials/path-finding/ It is much easier if you are using a grid, but if you aren't, then you are in for a long ride.Yes, that's a good explanation, now i know how it basically works, but to make it work in Smilebasic, i'll need to start up my brain lmao Thanks
I'm thinking about a top down (not with tile movement though) or a 2d map. Haven't made my mind yet but i think i'll be going with a 2d "room-to-room" game where (as the name suggests) you're gonna go from room to room, from door to door and i want the enemy to find a path and go through the doors too. I think it's actually gonna be easier than the top down game, which would be similar but with bigger rooms.
I don't really wanna spoil anything yet.
It sounds like you want to investigate the A Star or A* algorithm. It works well on a grid but is really more of a graph traversal algorithm. Moving from point to point has a cost so you can make going up a hill more expensive than a flat area. If you want impassable areas don't mark a position as a traversable node on the graph.
It starts out like Djikstra's search where you recursively evaluate nodes until you find a path to the target. However in A Star you have a heuristic function, so that you explore nodes that are better possibilities first. Once you find the target you backtrack your path. If your heuristic never overestimates you should have an optimal path. With a junk heuristic you devolve into Djikstras search performance.
This isn't a cheap operation so you should only really run it sparingly, not every frame.
As for being followed from room to room, you may just want to put the enemy on a timer and fake it. Only doing another search when the time says they should reach the room the user is in.
It sounds like you want to investigate the A Star or A* algorithm. It works well on a grid but is really more of a graph traversal algorithm. Moving from point to point has a cost so you can make going up a hill more expensive than a flat area. If you want impassable areas don't mark a position as a traversable node on the graph. It starts out like Djikstra's search where you recursively evaluate nodes until you find a path to the target. However in A Star you have a heuristic function, so that you explore nodes that are better possibilities first. Once you find the target you backtrack your path. If your heuristic never overestimates you should have an optimal path. With a junk heuristic you devolve into Djikstras search performance. This isn't a cheap operation so you should only really run it sparingly, not every frame. As for being followed from room to room, you may just want to put the enemy on a timer and fake it. Only doing another search when the time says they should reach the room the user is in.Yes, the timer would be a good solution... But not the best, because what if there are multiple doors in the room where the player is, how would it determine at which door it would appear?
And as for the pictures, i have prepared some poorly-made paintings on my phone but my mobile data are slow af and it won't upload, so i'll send it here as soon as i connect to wifi somewhereIf you post a picture, we can better understand what you are askingyes that's a good idea
I would calculate the door to enter from with the Pythagorean Theorem. For a right triangle with sides a, and b and hypotenuse c it states that a^2 + b^2 = c^2.
Let x1, y1 be the location the monster was (globally) at when you left them. Then for each door in the current room let x2, y2 be the (global) location of the door. dx = x2 - x1, and dy = y2 - y1 so calculate dx*dx + dy*dy and use the door that has the smallest resulting c^2 value.
All that being said, having a monster chasing you from room to room is pretty non-standard game behavior. I can't think of many games that do it, as it is pretty brutal. So I would of course use it very sparingly.