Hey guys, thought I'd share this with you. In my game, monsters appear as events on screen, and start battles when you come in contact with them. What I wanted to do is make it so that the monsters roam around freely, but chase you when you get too close to them. I was toying around with the events, trying to get everything working right, and finally pinned down a pretty good way to do it. This is completely script free (although I'm sure scripts might make this a little easier) and needs only 4+ variables to work.
I'll explain bits and pieces as needed, but the screenshots should be pretty self-explanatory.
First Page:
So, the bee flies around with the random move route setting, minding its own business. The event page sets the player's coordinates and the bee's coordinates to the 4 variables, and subtracts one from the other, giving the effective distance apart. Since the event is set to Parallel Process, it will continue calculating this in real-time until the Conditional Branch is met. In this example, it checks to see if the player is less than 4 tiles away in all four directions. Checking all four directions at once is very important.
If the conditions are met, it activates the second page of the event:
Second Page:
This is the chase page. The event's move route is set to approach the player at a steady pace. The same variables are stored and checked, only this time it is calculating two things. One, if the event steps onto a tile adjacent to the player, and two, if the player gets far enough away from the event. If the event reaches the player, the third page is activated, which is an autorun page that triggers the battle and so on. If the player gets enough distance from the event however, it reverts page to the first event page, effectively losing interest in you.
Things to note:
- Make sure after the third event page's processing is done that you shut off both of the self switches in reverse order (A, then B) so when you re-enter the map, it will be back on the first event page.
- Since most of the aspects of these events are integrated into the event page itself (type of event movement, distance required to chase/leave the player, etc.) you can make a whole host of events using this. You can have small animals that get spooked and run away from you when you get too close. Using a proper pathfinding script you could have guards chase you then return to their posts if you outrun them, etc.
- If you want more than one event like this on the same map, just use four more variables, so they can both calculate simultaneously without affecting each other.
If you have any questions or comments, feel free. Feedback is appreciated!
I'll explain bits and pieces as needed, but the screenshots should be pretty self-explanatory.
First Page:
So, the bee flies around with the random move route setting, minding its own business. The event page sets the player's coordinates and the bee's coordinates to the 4 variables, and subtracts one from the other, giving the effective distance apart. Since the event is set to Parallel Process, it will continue calculating this in real-time until the Conditional Branch is met. In this example, it checks to see if the player is less than 4 tiles away in all four directions. Checking all four directions at once is very important.
If the conditions are met, it activates the second page of the event:
Second Page:
This is the chase page. The event's move route is set to approach the player at a steady pace. The same variables are stored and checked, only this time it is calculating two things. One, if the event steps onto a tile adjacent to the player, and two, if the player gets far enough away from the event. If the event reaches the player, the third page is activated, which is an autorun page that triggers the battle and so on. If the player gets enough distance from the event however, it reverts page to the first event page, effectively losing interest in you.
Things to note:
- Make sure after the third event page's processing is done that you shut off both of the self switches in reverse order (A, then B) so when you re-enter the map, it will be back on the first event page.
- Since most of the aspects of these events are integrated into the event page itself (type of event movement, distance required to chase/leave the player, etc.) you can make a whole host of events using this. You can have small animals that get spooked and run away from you when you get too close. Using a proper pathfinding script you could have guards chase you then return to their posts if you outrun them, etc.
- If you want more than one event like this on the same map, just use four more variables, so they can both calculate simultaneously without affecting each other.
If you have any questions or comments, feel free. Feedback is appreciated!