Featured Post

Introduction

    Hello and welcome to the Spike Development Diary. Spike, as it is currently called, is a platform fighting game I (Chris Fabiano) am dev...

Saturday, May 16, 2020

Entry #2: Launching

    Two main things occur when a player gets hit in Spike. The first is that they receive some damage, which increases a number that keeps count of how much damage they have taken. The other thing is that they get launched. The distance that the player gets launched is based on multiple things and in this post we'll take a look at what those are.

    This image is a screenshot of the data for a hitbox. If you read the last post you'll remember that when a hitbox collides with another player, they will receive a hit based on the hitbox's info. All of the hitbox info is held in a JSON that is loaded into the player at the start of the match. Much of the info is used to determine the hitbox's location and lifespan but 5 of these parameters are what we'll be looking at here. Those parameters are angle, knockback, growth, damage, and hitstun.

    Angle & Knockback: These two numbers are used together to form the initial velocity of the launch. Some simple trigonometry is done to convert the knockback number into a 2D vector that points in the direction of the angle. Since the angle works as if 0° is facing forward and 90° is straight up and attacks can be used while facing either left or right, extra care had to be taken to correctly flip the angle so that it always sends the opponent the right way.

    Damage & Growth: When the hit connects with the opponent, they receive some damage. Every 10 damage received increases a player's "stage" by 1. Since the move in the screenshot deals 10 damage, the opponent's stage will always increase when they are hit. For each stage of damage a player has, the knockback received is multiplied by the attack they were hit with's growth. For example, if an opponent is hit with the move shown and has a stage of 3 after damage is dealt, the knockback they receive will be 9 x 1.25 x 1.25 x 1.25 or 17.57. This means that players will get launched farther as they take more damage, making attacks deadlier as the game goes on. The attack in the example has a very high growth rate, making it quite deadly at later stages, but different combinations of base knockback and growth can be used to make moves with a lot of different uses.

    Hitstun: This number represents a multiplier for the hitstun dealt by the attack. Hitstun is the amount of time the player is unable to act while flying through the air after being launched. It is calculated based on knockback, so as the knockback of a move increase, the hitstun will as well. Most attacks keep this number at 1 but sometimes it is useful to have a move with low knockback but disproportionately high hitstun or vice-versa.


    In addition to being launched, there are a few elements of the stage that have interactions with players flying into them. Let's take a look at what the code does when the player collides with the stage or the walls surrounding it.


    If the player's velocity is low enough, their hurtbox will be turned into a trigger. In Unity this means that it will not be physically repelled by other solid objects and just phase right though them. What this means for a player with intense negative y velocity is that they will fly right through the stage down to the bottom of the screen and die. The victim's velocity will also be reduced by 20%, so smashing through multiple platforms in a row is a made a little more difficult since you will be slower each time.
    What this means for the game is that if a player hits an opponent downwards with a soft hit while above the stage, the opponent will simply bounce off of it. If the hit is strong enough, however, the opponent will dramatically smash through the stage and continue on. Now let's look at what the code does when the y velocity is greater that -30.


    Once again, there is a velocity check. If the player is moving fast enough, the game will play a corresponding sound and visual effect like before and then flip the player's y velocity and reduce it by 40%. If the player is moving slow enough, they will safely land on the platform with no problem.
    This code is for when the player is colliding with the stage, but the walls and ceiling that surround the arena are also things that a player can bounce off of. The bouncing code for them is almost identical where their direction perpendicular to the object is flipped and reduced. The difference here being that walls and ceilings cannot be broken through or landed on, meaning they either bounce the player or do nothing.

No comments:

Post a Comment