reckfellENGINE

The 2D player prefab

Create a CharacterBody2D with a 28 × 28 shape, collision layer, mask and movement mode.

On this page

Create the hierarchy

Use File → Create Prefab… with a CharacterBody2D root, name it Player and save as Prefabs/Player.rprefab. Add a child CollisionShape2D:

Text
Player (CharacterBody2D)
└── CollisionShape2D

Create 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 propertyValueReason
Position(320, 180)Visible when running the prefab alone
Motion ModeFloatingTop-down movement without floor or gravity
Collision LayerLayer 1 onlyLets the hazard detect the player
Collision MaskAll offThis 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.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.