Behind The Code!
Hi Munchers! This post will provide you with some behind-the-scenes insight into the coding of Stay Hidden.
This post will be edited and updated as we continue development, so stay tuned!
PLAYER MOVEMENT
Basic Controller
To make the player move we first stored the player's horizontal value using:
horizontal = Input.GetAxis("Horizontal");
We could then alter the x velocity of the player's rigid body to make the player move left and right.
We then used the player's horizontal value to determine which way the player was facing and flipped the sprite accordingly.
Jump
The player is able to jump by pressing the "space" key. The longer they hold down the space key the higher the player will jump
We then used raycasting to ensure that the player can only jump when they are on the ground. To do this we used a raycast that would detect if the player was colliding with anything that had its layer tagged as ground.
We had issues with the player's jumping animation where the player occasionally got stuck in the falling animation. We had a third party help fix it by adding a separate ground check script that would change the animation.
PLAYER HEALTH
Players start with a set amount of health set to maxHealth. During the game, they will encounter and take continuous damage from enemies and damaging lights. Players will then need to seek out shadow areas to regenerate their health.
Shadows
When players are in a shadowed area, they steadily heal over time. The variable healthRegenCooldown determines how quickly the player can regenerate their health while in shadowed areas.
Damaging Lights
When players are in the red-coloured damaging light, they steadily take damage over time. This code is similar to the shadow code, but instead of increasing health, we decrease it.
ABILITIES
Hiding Ability
When a player presses the "Control" key they enter hiding mode. This sets the isHiding variable to true meaning that enemies are unable to damage or engage with the player. It also shrinks their box collider making the player able to squeeze into smaller spaces and go past enemies with colliders. Hiding also consumes stamina, when a player stops hiding or the stamina is completely depleted it begins to recharge.
Once the player stops pressing the control key the player's box collider resets to its original state.
Tail Whip
ENEMY AI
Player Detection Using Raycasting
Most enemies in the game use raycasting to detect the player. This will then trigger a unique response when the enemy sees the player. If the player is using the hiding ability or the player is in the shadows it sets the hidden variable to true. This means that enemies are unable to “see” the player if they are hidden. The variabe lineOfSightDistance is how far the enemy can see and the rayDirection refers to which direction they are facing (left or right).
Flipping The Sprite
To find out which direction the enemy is facing the script compares the change in the enemy's x position. If the new x position is less than the old position the enemy is moving left, so the sprite is flipped to face left and vice versa.
The Direction method then flips the enemy's line of sight (raycast) depending on which way the enemy is facing. If the enemy is moving left the rayDirection variable is positive, if the enemy is moving right the rayDirection is set to negative.
ENEMY TYPES
Butler
When idle the Butler patrols between 2 set points in the level.
When the Butler’s Ray cast hits the player, it triggers the Butler to chase the player. To do so it finds the position of the player and tells the Butler sprite to move towards that position.
Michael
Michael’s movements and mechanics are identical to the Butler’s but it runs away from the player. He patrols between two points and when the raycast detects the player it finds the position of the player and he moves away.
Maddie
Maddie is a stealthy enemy who spawns and attacks the player. She is inactive until the player collides with a trigger in the level, which activates her. She then spawns and chases the player. She chases the player until she collides with a wall or a set trigger, in which she despawns.
Mama + Maid
[To be Added]
Papa
[To be Added]
Grandma
[To be Added]
LIGHTS
Detecting Lights
When a player enters yellow lights, it alerts selected enemies toward the light. When the light alert variable is true it then sets the enemies Chase() method to true.
Alternating Lights
To make lights we created an array that would hold the game objects of the lights. The coroutine would alternate the lights by setting them active, waiting a set amount of time, then setting them inactive, and repeating.
Get Stay Hidden
Stay Hidden
Stay Hidden! Get back to your home in hell
Status | In development |
Authors | lizthegamedev, SH_Andy, TheMooncheese, Zenua |
Genre | Puzzle |
Tags | 2D, cultists, demon, Pixel Art, Puzzle-Platformer, Shadows |
More posts
- Released Demo5 days ago
- The Future of Stay Hidden!12 days ago
- New version of the game20 days ago
- 2 days to go for the Let's Break Games event!21 days ago
- Teaser and Tutorial Videos24 days ago
- We'll Be At Let's Break Games!26 days ago
- LORE! LORE! LORE!26 days ago
- Icons, Thumbnails and Graphics Design29 days ago
- Hunting for Bugs!45 days ago
Leave a comment
Log in with itch.io to leave a comment.