5 Implement Spring to the Game
We won't learn new thing here, but use our existing knowledge.
Few things we will understand is to make the collision shape a bit thicker to detect some speed object.
And way to detech the direction of the other interacting object
We have Added Area2D and a CollisionShape2D, We make sure to make the Shape thick as needed so when the player is falling from higher speed, it does not pass through.
We also make sure that the player is above while touching the area. In Godot the y axis is positive in down direction and negative in up direction.
func _on_area_2d_body_entered(body):
if body.global_position.y < global_position.y:
animated_sprite_2d.play("lunch")
body.high_jump()
pass # Replace with function body.
In the above code we play the "lunch" in the AnimatedSprite, Once the lunch animation is complete we need to show the default one, for that listen the animation_finished signal.
func _on_animated_sprite_2d_animation_finished():
if animated_sprite_2d.animation == "lunch":
animated_sprite_2d.play("default")
pass # Replace with function body.