Coin Collector: Walk
Part of the Signals and Collisions section of Coddy's Godot journey. Lesson 23 of 27.
Over the next five lessons you build Coin Collector. You walk around a room, take every coin, and win when the last one is gone.
The game has three scripts:
player.gd: the robot you move.coin.gd: every coin runs this one.main.gd: onMain, the game's rules.
First, walking. The player is a CharacterBody2D. The walls and the two grey blocks are StaticBody2D. You wrote this walker in the last section:
func _physics_process(delta):
velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") * SPEED
move_and_slide()move_and_slide() moves the body by its velocity and stops it at walls. Changing position yourself would walk through them.
Challenge
EasyMake the player walk with the arrow keys or WASD at SPEED pixels per second. The walls should stop it. Leave coin.gd and main.gd as they are.
Try it yourself
extends CharacterBody2D
const SPEED = 200.0
func _physics_process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Signals and Collisions
6Project: Coin Collector
Coin Collector: WalkCoin Collector: CoinsPractice on your own: Godot playground