Added rotatable laser weapon

This commit is contained in:
2ndbeam 2024-05-12 21:19:44 +03:00
commit 154da5104e
10 changed files with 99 additions and 13 deletions

View file

@ -3,6 +3,15 @@ extends Node2D
## Shortcut to get_parent()
@onready var ship: Ship = get_parent()
var expected_rotation: float = 0.0:
set(value):
if value > 180:
expected_rotation = value - 360
elif value < -180:
expected_rotation = 360 + value
else:
expected_rotation = value
func _physics_process(_delta) -> void:
ship.engine.acceleration_axis = Input.get_axis("deccelerate", "accelerate")
ship.engine.rotation_axis = Input.get_axis("rotateleft", "rotateright")
@ -12,4 +21,8 @@ func _physics_process(_delta) -> void:
weapon.shoot_request = Input.get_action_strength("shootprimary")
"secondary":
weapon.shoot_request = Input.get_action_strength("shootsecondary")
if "gun_rotation" in weapon:
var angle_to_mouse = ship.hull.position.angle_to_point(get_global_mouse_position())
expected_rotation = rad_to_deg(angle_to_mouse - ship.hull.rotation)
weapon.gun_rotation = expected_rotation