Setting up and moving the CharacterBody in 2D
In this recipe, we set up a 2D player character with the new CharacterBody2D node that replaced the kinematic bodies used in Godot 3.x. We will use free assets by Kenney for the player’s idle, jump, fall, and walk animation.
The CharacterBody2D node has a basic default movement script that we will add to the player and modify the script to show the animations.
Getting ready
For this recipe, click the + sign to the right of the Heightmap scene we just completed to add a new scene. In the Scene tab, click on Other Node, and in the Search box that appears, type cha
and select CharacterBody2D, then click the Create button. Now, we have CharacterBody2D as the base node for this scene. Click on the word Scene in the main menu next to Project, then select Save Scene As and name it Player2D
.
Download Platformer Characters by Kenney from https://www.kenney.nl/assets/platformer-characters and extract it to a new folder.