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.

Time System with Random NPC Movement

OK, here's the situation.  I've made a time system using only events (which I will release in a tutorial after I submit the piece in Gaming World's contest) and I'm using switches to control lights and such.  What I need to know is if it is possible to make a character walk toward an area from wherever he is.  I have a person walking at random outside, and I'd like him to walk over to his house when a switch comes on signaling night.  I was thinking of using something with variables, but I'm not sure where to start.  Thanks for reading. :thumb:

~Guardian1239
 
Hmm, I think I know a method for this. Unfortunately, it will use about 50 variables and 500 conditional branches for every single town.

But here it is anyway.
Code:
@>Control Variables: [0001: NPC X] = NPC's Map X
@>Control Variables: [0002: NPC Y] = NPC's Map Y
@>Control Variables: [0003: Door X] = Door's Map X
@>Control Variables: [0004: Door Y] = Door's Map Y

@>Control Variables: [0001: NPC X] -= [0003: Door X]
@>Control Variables: [0002: NPC Y] -= [0004: Door Y]

That code stores the coordinates of the NPC event and the Door event in variables, then subtracts the Door value from the NPC value. That basically gives you the distance between the two events. If the value is positive, the NPC is to the right of or below the Door; if the value is negative, the NPC is to the left of or above the door.

After that, you could do a series of conditional branches checking the distance and using "Set Move Route" to make the NPC walk to the door.

And there you have it. An extremely tedious and time-consuming event system. Now, there are STILL bugs with this-- making the NPC avoid trees, water, stuff like that. But that's about as far as you can get with eventing (unless you want to check if the player is near every single impassable tile and work off that).

Basic summary: scrap that idea. Use a pathfinding script.
 

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