Rewriting ships: Movement system

This commit is contained in:
2ndbeam 2024-04-28 18:53:09 +03:00
commit e2b9fa6c69
10 changed files with 208 additions and 0 deletions

26
scripts/Ship/engine.gd Normal file
View file

@ -0,0 +1,26 @@
extends Node2D
class_name ShipEngine
# TODO: implement dashes
# TODO: make particles and turbo
## Engine ID to use with Game.get_module
@export var id: String = "engine"
## Acceleration speed of the engine
@export var acceleration_speed: float = 50.0
## Rotation speed of the engine
@export var rotation_speed: float = 5000.0
## Shortcut to get_parent()
@onready var ship: Ship = get_parent()
## Acceleration control variable
var acceleration_axis: float = 0.0
## Rotation control variable
var rotation_axis: float = 0.0
func _physics_process(_delta):
# apply movement and rotation
ship.hull.apply_central_force(Vector2.from_angle(ship.hull.rotation) * acceleration_speed * acceleration_axis)
ship.hull.apply_torque(rotation_speed * rotation_axis)