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.

Sneaking past guards

Hi, I'm making a mission in my game where you have to get past guards without getting caught. You have to time your movements and walk past them when they're not looking. I've gotten half of it working correctly. Here's what I have thus far:
eventpg.jpg


The guard "sees" the player when he is facing left, but I don't know how to make it so that, when he faces right, the principles apply the same way, except you can pass him without getting caught, but you DO get caught if he sees you from the right when he's facing right.

I hope that wasn't too confusing lol.

I have other guards that face different directions, but I only need help with this because when I understand how to do it with two directions, I'm sure I'll be able to deal with other directions.
 

Tuna

Awesome Bro

Please redirect to http://www.arpgmaker.com/viewtopic.php?p=670030#p670030 for a more updated version of this event code.

Basically I set Hero X and Y variables and Event X and Y variables like you did. I put all of the coding inside the guard so it's easy to keep track of, and you can set its variables more easily (This Event's...). Here's the technical stuff:
iseeyoucode.png
Alternatively, here's a snippet of the code:

If facing left...
If Player Y = Event Y
If Player X < Event X
Set Hero X Check = Player's Map X
Set Event X Check = Event's Map X
Event X Check - Hero X Check
If Event X Check >= 1(Greater or Equal)
If Event X Check <= 5(Less or Equal)
Text: I see you!

This will make the guard notice the player if they are within 5 tiles of the guard. The reason for setting the checks is due to the fact that you can't check differences, only one variable. To solve this, I made Check variables that check the player and event's current locations, subtract, and see if the result is within a range of 5. IT IS IMPORTANT to make these variables separate from the Hero X/Y and Event X/Y variables because every guard event that you have running on the map needs to run this check, and they can't all be subtracting and testing the same variables.

Using this system of checks, you can give your guards any motion path you wish, but you will have logic problems if there is an object between the guard and the player, because the guard will not detect the object. To get around this you can set your guards' motion paths so that they will not be in a position to look through objects, or you can adjust the ranges if you know a stationary guard will be looking through an object in one direction.

If you would like to change the guard's vision range, simply adjust the final check,
If Event X Check <= 5(Less or Equal).
If you wanted the guard to see 10 tiles ahead, change 5 to 10. If you'd only like the guard to see 3 tiles ahead, change 5 to 3, etc.

If anyone notices any problems with my code, please let me know. It worked fine when I tested it, but I'm not perfect. Good luck with your project!
 

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