Skip to main content

Chapter 6a - Bodies (mocked)

Body types in Godot 2D​

In a real project you pick a physics body for how something should move:

Godot classRoleKit mock
CharacterBody2DPlayer / NPCs you move in codeKit.CharacterBody / make_character
StaticBody2DWalls, floors β€” never pushedKit.StaticBody / make_static
RigidBody2DBoxes, barrels β€” engine integrates forcesKit.RigidBody / make_rigid

This sandbox has no physics server. The kit mocks share the same ideas (velocity, gravity, move_and_slide) so you can practice the APIs.

var Kit = preload("res://game_kit.gd")
var hero = Kit.make_character(Vector2(0, 0), 0.0) # floor at y=0
hero.velocity = Vector2(50, 0)
hero.move_and_slide(1.0)
print(hero.position, hero.is_on_floor())
πŸ§ͺ Character walk on a floor

CharacterBody: velocity then slide​

Pattern (same as Godot tutorials):

  1. Set velocity (from input, AI, knockback)
  2. Optionally apply_gravity(delta)
  3. Call move_and_slide(delta)

Jump only works when is_on_floor() is true.

πŸ§ͺ Jump then fall

Mini quiz β€” bodies​

Quiz

Body types

1 / 3

Which body do you usually code movement for each frame?

Pick an answer to see if you are right.

StaticBody vs RigidBody​

Static ignores velocity β€” good for platforms.

Rigid integrates gravity each integrate(delta) and can take apply_impulse.

πŸ§ͺ Drop a rigid box

Challenge: one second walk​

Make a character on floor y=0, set velocity = Vector2(25, 0), call move_and_slide(1), print int(position.x).

Expected: 25.

Exercises​

Activity: Still on floor

make_character(Vector2(0, 0), 0.0) starts on the floor. Print true if is_on_floor() without moving.

true