Add a new Script to the Player node
gravity
run speed
jump speed
Create the change state function
Use variables to represent the different input actions
Now move in the correct direction
Flip the sprite if required
If we are still and start moving
Change states from idle to run
Show the falling animation
Create a new scene with Node2D as root
Add a StaticBody2D node renamed to Platform
Add a new CollisionShape2D as child
Add a new RectangleShape2D and cover the platform
Add an instance of the Player
Arrange them in the scene for testing
Go to Debug => Visible Collision Shapes
Save the scene as main.tscn
set it to the set_life function
This will run the function whenever
Update the Reset function
To Set default lives to 3
To transition to hurt state
in the get input function
Edit the change state function
The code executes a classic arcade-style damage reaction: it plays a visual reaction, knocks the character back and up, subtracts health, and temporarily freezes control before returning to idle.