Menu
CoddyTech

Fire the Engine

Part of the Projects section of Coddy's Godot journey. Lesson 11 of 33.

Up fires the engine and pushes the ship the way its nose points. Vector2.UP is (0, -1). rotated(rotation) turns that arrow as far as the ship has turned:

if Input.is_action_pressed("move_up"):
	velocity += Vector2.UP.rotated(rotation) * THRUST * delta
position += velocity * delta

The engine changes the velocity, not the position. When you let go of Up, the ship keeps drifting. To stop, turn around and thrust the other way.

The ship has a hidden Flame child. Show it while the engine fires: $Flame.visible = Input.is_action_pressed("move_up").

challenge icon

Challenge

Medium
  1. Add const THRUST = 300.
  2. While Up is held, add Vector2.UP.rotated(rotation) * THRUST * delta to the ship's velocity.
  3. Move the ship by velocity * delta every frame, held or not.
  4. Show $Flame only while Up is held.

Try it yourself

extends CharacterBody2D

const TURN_SPEED = 4.0

func _physics_process(delta):
	rotation += Input.get_axis("move_left", "move_right") * TURN_SPEED * delta
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Projects

Practice on your own: Godot playground