Charge - UQdeco2800/2022-studio-2 GitHub Wiki

Back to Skills

Charge Code

Charge details

The charge skill upon use causes the player to burst forward in the currently facing direction. If the player collides with an enemy then the enemy is knocked back and damaged. The skill is intended to close distance between enemies and quickly deal a lot of damage (30) to a single enemy. It has a higher cooldown/mana cost compared to other skills to balance this. The enemy is knocked back on collision so the player doesn't immediately take damage after the skill is used.

Charge movement

The movement of charge is almost identical to the dash skill. The only differences are that charge is significantly faster, and charge movement is interrupted if the player collides with an enemy.

Applying knockback to enemy

The knockback is applied using box2d impulse and the strength of the knockback is set through the setLength() function. Enemies with a chase task are affected by impulse less because they are moving in the opposite direction to the impulse. This was adjusted for by setting a stronger impulse for gymbros (gymbros are the only enemy in the game with a chase task). A boolean in the initial call function is used to ensure only one enemy can be hit at a time.

if (physicsComponent != null) {
    Body targetBody = physicsComponent.getBody();
    Vector2 direction = target.getCenterPosition().sub(playerEntity.getCenterPosition());
    Vector2 impulse;
    if (target.checkEntityType(EntityTypes.MELEE)) {
        impulse = direction.setLength(100f); // knockback strength (gymbro)
    } else {
        impulse = direction.setLength(40f); // knockback strength (not gymbro)
    }
    targetBody.applyLinearImpulse(impulse, targetBody.getWorldCenter(), true);
}