Chapter 6a - Bodies (mocked)
Body types in Godot 2Dβ
In a real project you pick a physics body for how something should move:
| Godot class | Role | Kit mock |
|---|---|---|
CharacterBody2D | Player / NPCs you move in code | Kit.CharacterBody / make_character |
StaticBody2D | Walls, floors β never pushed | Kit.StaticBody / make_static |
RigidBody2D | Boxes, barrels β engine integrates forces | Kit.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):
- Set
velocity(from input, AI, knockback) - Optionally
apply_gravity(delta) - Call
move_and_slide(delta)
Jump only works when is_on_floor() is true.
π§ͺ Jump then fall
Mini quiz β bodiesβ
Body types
1 / 3Which 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