Turn the Ship
Part of the Projects section of Coddy's Godot journey. Lesson 11 of 36.
The next project is an asteroid shooter. A ship turns, thrusts and shoots drifting rocks. You win when no rocks are left, and lose if one hits the ship.
The scripts are ship.gd, rock.gd and main.gd. Start with the ship. It does not slide like the paddle. It turns: Left and Right change its rotation, in radians.
rotation += Input.get_axis("move_left", "move_right") * TURN_SPEED * deltaA full turn is about 6.28 radians. With a TURN_SPEED of 4, a full turn takes about a second and a half. A positive rotation turns clockwise.
Challenge
EasyTurn the ship with the arrow keys.
- In
ship.gd, addconst TURN_SPEED = 4.0. - In
_physics_process, turn the ship with Left and Right atTURN_SPEEDradians per second. Right turns it clockwise.
Press Play and hold Right: the ship spins clockwise. Then Check.
Try it yourself
extends CharacterBody2D
func _physics_process(delta):
pass
All lessons in Projects
2Project: Asteroid Shooter
Turn the ShipFire the EnginePractice on your own: Godot playground