From bfefcffb1fba60cfe6bb87a28fadb1af1bd20d62 Mon Sep 17 00:00:00 2001 From: Foohoo Date: Wed, 22 Oct 2025 12:33:50 +0100 Subject: [PATCH] add player bounce when killing enemy --- scenes/slime.tscn | 1 + scripts/hit_box.gd | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scenes/slime.tscn b/scenes/slime.tscn index 3d543aa..cbba1ec 100644 --- a/scenes/slime.tscn +++ b/scenes/slime.tscn @@ -271,6 +271,7 @@ animation_player = NodePath("../AnimationPlayer") animation_name = "die" animated_sprite = NodePath("../AnimatedSprite2D") animated_sprite_name = "die" +player_bounce = -200 [node name="CollisionShape2D" type="CollisionShape2D" parent="HitBox"] position = Vector2(0, -11) diff --git a/scripts/hit_box.gd b/scripts/hit_box.gd index 08338d5..d48500f 100644 --- a/scripts/hit_box.gd +++ b/scripts/hit_box.gd @@ -6,6 +6,11 @@ extends Area2D @export var animated_sprite: AnimatedSprite2D @export var animated_sprite_name: String -func _on_body_entered(_body: Node2D) -> void: +@export var player_bounce: int + +func _on_body_entered(player_body: Node2D) -> void: + var player_character_body = player_body as CharacterBody2D + player_character_body.velocity.y = player_bounce + animated_sprite.play(animated_sprite_name) animation_player.play(animation_name)