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

@ -19,6 +19,13 @@ var destination_degrees: float = 0:
destination_degrees = value
## Delta to destination_degrees
var destination_difference: float = 1.0
var current_destination_difference: float:
set(value):
if value > 180:
current_destination_difference = value - 360
else:
current_destination_difference = value
## available map bounds (use with absolute position)
var available_bounds: Vector2
# for testing purposes only
@ -35,11 +42,9 @@ func enter(_message):
func process(_delta):
# checking if need to apply torque
var current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
var other_destination_difference = ship.hull.global_rotation_degrees - destination_degrees
var min_difference = min(abs(current_destination_difference), abs(other_destination_difference))
if min_difference > destination_difference:
ship.engine.rotation_axis = min_difference / 180
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
if abs(current_destination_difference) > destination_difference:
ship.engine.rotation_axis = clamp(current_destination_difference / 360 + 0.5 * sign(current_destination_difference), -1.0, 1.0)
else:
ship.engine.rotation_axis = 0.0
# making ship always accelerate