🧪 Code Sandbox

Experiment with GDScript code patterns

Powered by CodeMirror
📚 Examples
📄 player_movement.gd GDScript
extends CharacterBody2D

@export var speed := 300.0
@export var jump_force := -400.0

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta: float) -> void:
# Apply gravity
velocity.y += gravity * delta
# Jump when on floor
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_force
# Horizontal movement
var direction := Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
move_and_slide()
🏃

Player Movement

Basic platformer movement with jump

📝 Key Concepts

  • CharacterBody2D - Physics body for player control
  • move_and_slide() - Built-in movement function
  • is_on_floor() - Ground detection
  • @export - Expose to Inspector