Confidentiality Dev Log 1: Player Script

This script is the one that controls the majority of the functions of the player object in the game. The top part of the script shows all of the variables needed for the script to function correctly. The ‘rb’ variable refers to a rigidbody2D that will later be linked to the player. The two check variables refer to empty objects that are used to detect either a pipe or ceiling. The ‘crouchDisableCollider’ variable refers to the top collider of the player so that it can be disabled and let the player crouch. The ‘playerAnimator’ links to the animator of the player so animations can be played when certain functions are used. The two ‘LayerMask’ variables link to layers in the game so that the pipes and ceilings are able to be detected. The ‘input’ variables are used to allow the player to move horizontally and vertically. The three bool variables are used to determine different things about the player so that parts of the script know when they are supposed to activate. The ‘speed’ variable is a float that is used to determine the player’s speed while the ‘Radius’ variables are floats that determine the size of a radius around an object that detects the ceiling and pipes. The next part of the script is about creating a bool and event that can be used to play an animation when the player is crouching. The ‘private void Awake’ section links the ‘rb’ to the player rigidbody2D as well as some additional code needed for the bool event linked to the crouch animation.

This section (public void Move) contains code that controls certain aspects of the player. The first part determines whether the player is underneath a ceiling while crouching so the player object doesn’t play an animation where the player is stood up. The second part controls the functionality for the crouch as well as the crouch animation. The last part makes sure the player is facing the right way when moving by linking to the ‘Flip’ function.

This part of the script adds functionality to the ‘Flip’ function so that it will actually flip the player as well as linking a bool variable from this script to a bool variable in the animator connected to the player so that the animation will play at the right point.

This ‘void Update’ section is used to create the functionality for most of the actions the player can do in the game as the Update part makes it so the script will always be checking for the input so the player actions are never delayed. It starts by linking the A and D keys to horizontal movement using the ‘Horizontal’ tag and then determines the speed of this movement as well as linking the input to a float in the player animator so that the walk animation will play while the player moves and so an idle animation will play when they don’t. The next part links the C key to the crouch function so that whenever the C key is held down the player will crouch. This next part allows the player to climb pipes by enabling the ‘isClimbing’ bool when the player is in the radius of the pipe layer and they press the W or S keys and then disabling it when they aren’t in the radius anymore. After this, the ‘isClimbing’ bool is connected to the code for climbing using an if statement. If ‘isClimbing’ is true the W and S keys will now control the movement of the player vertically, the speed of the player will be added to vertical movements, the gravity of the player will be set to 0 so they don’t get dragged down while gravity while on a pipe and a bool connected to the climbing animation in the player animator will be set to true so that the climbing animation plays. If ‘isClimbing; is then set to false the vertical movement functionality will be removed, the gravity of the player is returned to 2 and the climbing bool in the player animator will be false so the animation stops.

The rest of the player functionality is contained in scripts that are connected to the game objects that the player interacts with rather then on the player object. These functions are the ability to open vents/trap doors using the E key and the ability to drop from a horizontal pipe by holding the Space bar.