Made kamikaze behavior and also fixed borders
This commit is contained in:
parent
ac263a1e65
commit
1ee0b529a8
10 changed files with 41 additions and 44 deletions
|
|
@ -17,16 +17,16 @@ var destination_degrees: float = 0:
|
|||
destination_degrees = 360 + value
|
||||
else:
|
||||
destination_degrees = value
|
||||
## Difference between current rotation and destination angle, in degrees. Sign determines torque direction.
|
||||
var current_destination_difference: float = 0:
|
||||
set(value):
|
||||
if value < 0:
|
||||
current_destination_difference = 180 + value
|
||||
if current_destination_difference > 180:
|
||||
current_destination_difference = value - 180
|
||||
## Delta to destination_degrees
|
||||
var destination_difference: float = 5.0
|
||||
|
||||
var current_destination_difference: float:
|
||||
set(value):
|
||||
if value > 180:
|
||||
current_destination_difference = value - 360
|
||||
else:
|
||||
current_destination_difference = value
|
||||
|
||||
func enter(message: Dictionary):
|
||||
if message.has("target"):
|
||||
target = message["target"]
|
||||
|
|
@ -37,9 +37,8 @@ func process(_delta):
|
|||
# checking if need to apply torque
|
||||
destination_degrees = rad_to_deg(ship.global_position.angle_to_point(target.global_position))
|
||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||
var rotation_sign = sign(current_destination_difference)
|
||||
if abs(current_destination_difference) > destination_difference:
|
||||
ship.engine.rotation_axis = rotation_sign * (current_destination_difference / 180)
|
||||
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
|
||||
ship.hull.apply_central_force(Vector2.from_angle(ship.hull.rotation) * additional_stab_force)
|
||||
|
|
|
|||
|
|
@ -17,15 +17,8 @@ var destination_degrees: float = 0:
|
|||
destination_degrees = 360 + value
|
||||
else:
|
||||
destination_degrees = value
|
||||
## Difference between current rotation and destination angle, in degrees. Sign determines torque direction.
|
||||
var current_destination_difference: float = 0:
|
||||
set(value):
|
||||
if value < 0:
|
||||
current_destination_difference = 180 + value
|
||||
if current_destination_difference > 180:
|
||||
current_destination_difference = value - 180
|
||||
## Delta to destination_degrees
|
||||
var destination_difference: float = 15.0
|
||||
var destination_difference: float = 1.0
|
||||
## available map bounds (use with absolute position)
|
||||
var available_bounds: Vector2
|
||||
# for testing purposes only
|
||||
|
|
@ -42,10 +35,11 @@ func enter(_message):
|
|||
|
||||
func process(_delta):
|
||||
# checking if need to apply torque
|
||||
current_destination_difference = destination_degrees - ship.hull.global_rotation_degrees
|
||||
var rotation_sign = sign(current_destination_difference)
|
||||
if abs(current_destination_difference) > destination_difference:
|
||||
ship.engine.rotation_axis = rotation_sign * (current_destination_difference / 180)
|
||||
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
|
||||
else:
|
||||
ship.engine.rotation_axis = 0.0
|
||||
# making ship always accelerate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue