Menu
CoddyTech

Fire the Engine

Part of the Projects section of Coddy's Godot journey. Lesson 12 of 36.

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

Make the engine push the ship.

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

Press Play and hold Up: the flame burns and the ship drifts on after you let go. Then Check.

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

All lessons in Projects

Practice on your own: Godot playground