Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Events Chasing Player [Guide]

SPN

Member

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:
2q9ba1c.png


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:
200g12.png


2v11c0j.png


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 had actually thought about doing that myself. While that will work, I do believe it's rather inefficient. I do believe there was something posted forever and a day ago that showed a better way to do it. Let me see if I can dig it up.

EDIT: Never mind. What I was thinking about could work but you'd have to be rather crafty and it probably wouldn't be the best idea. However, what you've shown does seem to be far too clunky. Surely there must be a better way to do this.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top