A Patrolling Guard
Part of the Projects section of Coddy's Godot journey. Lesson 29 of 33.
A guard stands behind the door: a red slime, in enemy.gd. It walks up and down without stopping. A direction of 1 means down, and -1 means up:
position.y += SPEED * direction * delta
if position.y > 320 or position.y < 70:
direction = -directionFlipping direction at either end turns the guard around.
A guard on a fixed path is fair. The player can watch it, learn its timing and get past.
Challenge
EasyIn enemy.gd:
- Add
const SPEED = 80andvar direction = 1. - Every physics frame, move the guard by
SPEED * direction * deltaony. - Flip
directionwhenyis over 320 or under 70.
Try it yourself
extends Area2D
func _physics_process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
1Project: Breakout
Breakout PaddleKeep the Paddle on Screen4Project: Dungeon Crawler
Walk the DungeonPick Up the KeyPractice on your own: Godot playground