diff --git a/Scripts/hiro_ai.gd b/Scripts/hiro_ai.gd index cc2bd88..5871a10 100644 --- a/Scripts/hiro_ai.gd +++ b/Scripts/hiro_ai.gd @@ -108,12 +108,8 @@ func _on_hurt_state_entered(): else: set_animation_direction(facing_direction) anim_playback.travel("hurt") - var knockback_variance = Vector2.ZERO - if attacked_from.x != 0: - knockback_variance.y = randf_range(-1, 1) * KNOCKBACK_RANDOMNESS - elif attacked_from.y != 0: - knockback_variance.x = randf_range(-1, 1) * KNOCKBACK_RANDOMNESS - velocity = attacked_from * KNOCKBACK_POWER + knockback_variance + var knockback_direction = attacked_from.rotated(deg_to_rad(randf_range(-1, 1) * KNOCKBACK_RANDOMNESS)) + velocity = KNOCKBACK_POWER * knockback_direction.normalized() state_machine.set_expression_property("melee_stage", 0) diff --git a/Scripts/hiro_player.gd b/Scripts/hiro_player.gd index 34c7ba1..1fda254 100644 --- a/Scripts/hiro_player.gd +++ b/Scripts/hiro_player.gd @@ -88,12 +88,8 @@ func _on_enemy_attack_did_hit(other, power, attack_direction): else: var facing_direction = attack_direction * -1.0 set_animation_direction(facing_direction) - var knockback_variance = Vector2.ZERO - if attack_direction.x != 0: - knockback_variance.y = randf_range(-1, 1) * KNOCKBACK_RANDOMNESS - elif attack_direction.y != 0: - knockback_variance.x = randf_range(-1, 1) * KNOCKBACK_RANDOMNESS - velocity = KNOCKBACK_POWER * attack_direction + knockback_variance + var knockback_direction = attack_direction.rotated(deg_to_rad(randf_range(-1, 1) * KNOCKBACK_RANDOMNESS)) + velocity = KNOCKBACK_POWER * knockback_direction.normalized() var playback: AnimationNodeStateMachinePlayback = $AnimationTree.get("parameters/playback") playback.travel("hurt")