The 2D player prefab
Create a CharacterBody2D with a 28 × 28 shape, collision layer, mask and movement mode.
Create the hierarchy
Use File → Create Prefab… with a CharacterBody2D root, name it Player and save as Prefabs/Player.rprefab. Add a child CollisionShape2D:
Player (CharacterBody2D)
└── CollisionShape2DCreate a RectangleShape2D in CollisionShape2D.Shape with size (28, 28). Keep its local position at (0, 0) and Disabled off. The shape is physics data and is not drawn during ordinary play.
Root properties
| Player property | Value | Reason |
|---|---|---|
Position | (320, 180) | Visible when running the prefab alone |
Motion Mode | Floating | Top-down movement without floor or gravity |
Collision Layer | Layer 1 only | Lets the hazard detect the player |
Collision Mask | All off | This prototype has no solid obstacles |
The numeric layer and mask values are 1 and 0; the inspector presents them as bit buttons. Distinguish the layer a body occupies from the mask it searches.
Keep the child shape scale at (1, 1) and change RectangleShape2D.Size to match the scripted drawing. Moving the shape relative to the root shifts collision without moving the _Draw() square.
Visible graphics
_Draw() in DodgePlayer.cs draws a blue square with the same 28 × 28 bounds. No Sprite2D, texture or art archive is required. A shape alone will not show a character until the script is attached and built.
After adding the code, build and run the prefab with F6. The square should appear in the center and move. In the complete level, the Player instance uses (320, 300) as a local position override, not a change to the original type.
If hazards do not detect the player, check the shape, the player's layer 1 and the hazard Area2D mask 1. The player's own mask need not be enabled for that detection. See physics and collisions.