Dodge Design - UQdeco2800/2022-studio-2 GitHub Wiki
The dodge was designed to be a quick backward/sideways movement in the direction opposite to player movement. This was also inspired by fighting games and (observationally) the way people play them, where a quick and unexpected backwards dash/dodge is a useful tool in a player's toolkit. In order to make this functionally different from the dash skill, emphasis on the sideways movement of the player was implemented.
Similar to the block skill where cooldowns are reduced on damage, when damage is mitigated with the dodge, it provides a short movement speed boost to the player. This can be triggered when checking for skill invulnerability with skillDamageTrigger(), which is functionally the same as isInvulnerable() however also triggers mitigated damage triggers to the skills state.
To emphasise the design of the dodge to have greater sideways movement, the first design challenge was to isolate the sideways movement from the movement of the player input at time of pressing the dodge (regardless of direction of dodge start). This was done by saving the direction of movement at time of dodge start, and adjusting player speed by a normalised vector dot product of the original movement and the direction the player attempts to move after starting the dodge. This was using the property of the vector dot product, where: a dot b = |a| * |b| * cos(angle_between_vectors). We can see here that if the two vectors are normalised (of magnitude 1), that the vector dot product (a dot b) is equivalent to the cosine of the angle between those two vectors. From here we know the range of cosine is between a value of -1 and 1, with 0 being the value of cosine when the vectors perpendicular and 1 being the value of cosine when they are parallel. This range allowed for a scaling of the movement speed in this perpindicular directions with (1 - |cos(angle_between_vectors|). This only produces values between 0 and 1, with 0 being when the angle between the vectors are 0deg or 180deg and 1 when the vectors are perpendicular to the starting direction of the dodge. The vector dot product implementation is below:
private float vectorDotProduct(Vector2 firstVector, Vector2 secondVector) {
Vector2 normFirstVector = normaliseVector(firstVector);
Vector2 normSecondVector = normaliseVector(secondVector);
return ((normFirstVector.x * normSecondVector.x) + (normFirstVector.y * normSecondVector.y));
}
The movement modifier for the dodge as a result of this dot product is below:
if (isDodging()) { // Dodging has priority over dash (can interrupt dash with a dodge)
Vector2 dodgeVelocity = dodgeDirection.cpy().scl(DODGE_SPEED);
float vectorDotProduct = vectorDotProduct(modifiedMovementVector, dodgeVelocity);
Vector2 alteredMovement = new Vector2(modifiedMovementVector.x * (1 - Math.abs(vectorDotProduct)) * DODGE_SIDE_MOVE,
modifiedMovementVector.y * (1 - Math.abs(vectorDotProduct)) * DODGE_SIDE_MOVE);
modifiedMovementVector = addVectors(alteredMovement, dodgeVelocity);