Change knockbacks from random offsets to rotated vectors at random angles

This commit is contained in:
Raxki 2024-09-18 15:29:56 -04:00
parent 31529ecbd4
commit 152bd48a35
2 changed files with 4 additions and 12 deletions

View file

@ -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)

View file

@ -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")