Player ship
The player ship is the heart of the game. Most of the code you'll write for this project will be about making the ship work. It will be controlled in the classic Asteroids style, with left/right rotation and forward thrust. It will also detect the shoot input to allow the player to fire the laser and destroy the floating rocks.
Body setup and physics
Create a new scene and add a RigidBody2D
named Player
as the root node, with Sprite
and CollisionShape2D
children. Add the res://assets/player_ship.png
image to the Texture
property of the Sprite
. The ship image is quite large, so set the Scale
property of the Sprite
to (0.5, 0.5)
and its Rotation
to 90
.
Note
The image for the ship is drawn pointing upwards. In Godot, a rotation of 0
degrees points to the right (along the x axis). This means you need to set the Rotation
of the Sprite
node to 90
so it will match the body's direction.
In the Shape
property of CollisionShape2D
, add a CircleShape2D
and scale it to cover the image as closely...