Postmortem of Ability System and Boss FIght


By Roy Yang

Ability System

1.Double Jump

Double jump is programmed simply by specifying the number of jumps and updating with the ground check.

2.Wall Climb

To let the player climb the wall, first, the player-wall collision should be detected. Physics2D.BoxCast for both player’s left and right is used for this detection.

3.Flash => Dash

Raycast can be used for the teleport (flash) ability. However, it won’t show the player’s quick dashing. Therefore, I use an exact AddForce to let the character move fast while is not hard to follow. The velocity is then set to zero after a fixed distance or hit the wall.

4.Grapple hang

The grapple is made by Physics2D.Raycast, Distance Joint 2D, and Line Renderer, from the player position to mouse position on the screen. To let the player hanging with grapple length not change, autoConfigureDistance is set to true.

5.Grapple drawn

Most of the settings of grapple drawn are similar to the hanging, the only difference is that the autoConfigureDistance is set to false so the grapple length is decreasing and thus drawing the player to the raycast point.

Boss Fight

StateMachineBehaviour + MonoBehaviour + Animations

  • Random idle time is set on entering the idle state. In the state, the time counts down. Once the timer reaches 0, the boss is set to the Jumping state.
  • Random numbers of millions are summoned on entering the Jumping state. At the time, both boss’s position and the player’s position are documented for later use. In the state, the boss will move towards from his initial position x to the player’s position x at a constant speed, while the boss’s y position is based on the preset jumping animation.
  • When the boss is idle, the player can shoot the boss’s legs with separate leg colliders and cause damage (boss shift to legshot state and shift back); when the boss is jumping, the leg goes in and thus won’t be damaged.

Setbacks & Solutions

  1. The first jump animation of changing the sprites may not act correctly because of the ground check error when the player starts jumping while the ground-check still returns grounded. To fix that, a boolean variable “jumpStarts” is set to True once the player presses the jump button and is set to False in an IEnumerator after 0.5 seconds. Ground-check will only work when “jumpStarts” is false.
  2. The wall climbing has a timer. However, when the player is not grounded, he should not have more than once climbing. If no limit is set, the player may simply off the wall for one frame time and then he will have a refreshed wall climbing timer. Therefore, I use 3 variables climbStarts, isClimbing and climbEnds, as well as the wall detection variable hitWall to ensure that the player has only one chance of climbing in the air.
  3. The grapple hang starts and ends by pressing E, while the grapple drawn is designed to only start by right click and will automatically end when the player is drawn to the near position. However, sometimes the grapple joint is in the collider’s crack that will end up slowly moving the player to the position without the end. Hence, a Coroutine is used to let the player manually end the grapple drawn after 1 second, which for most cases, 1 second is the time the grapple drawn ends automatically.
  4. The boss is designed to jump to the player’s position, with y coordinate animating as a normal jump and x coordinate moving forward to the player. However, the animation cannot only apply to the y coordinate, the scrip changing x coordinate will be overridden by the animation. Therefore, I create an empty parent for the boss and let the animation works on the boss itself while moving the boss parent x coordinate, which works. 

Future work

  1. Create more the Boss Fight stages. Set more separate colliders for the boss (body, legs, eyes, etc) that get different damages in different states.
  2. Create more Boss attacking ways, like shooting lasers, firing fires that also stay in the scene for a while, holding weapons, etc.
  3. Let the boss fight scene change with boss fight stages to create more variety.
  4. Add more sound effects responding to the player’s state.

Files

swagBuild.zip Play in browser
Nov 10, 2021

Leave a comment

Log in with itch.io to leave a comment.