Log In  

I can't seem to find any tutorials on how to make monsters move or patrol or have movements routines.

Nothing fancy, something like:

Go from A to B, wait a few frames, go to C, wait again, go back to A and repeat.

The monster doesn't even have to notice the player, just walk its path.

I've tried with loops but I can't make it work.

Thank you very much!!! :D

P#62071 2019-02-19 13:42

What have you considered so far?

One simple approach:

Store the positions for each monster: Its current position, plus a table with all the stops in the patrol, and finally a variable that just holds the index in the stop table that contains the current goal.

Then, each frame, make the monster's current position closer to the goal. If it reaches the goal, increment the goal variable so the next stop becomes the goal. (Use the modulo operator % to wrap around to the first stop again when it has reached the last one.)

Of course, how you make the monster move towards the goal is the tricky part. Do you need a path finding algorithm (like A*)? There are lots of different possible approaches here.

P#62072 2019-02-19 14:22 ( Edited 2019-02-19 14:23)

Thank you tobias!

Your solution looks perfect! I don't think I know enough to do that yet but ill try it in the future! :)

P#62080 2019-02-19 16:22

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-03-25 23:20:21 | 0.005s | Q:11