@@ -3,57 +3,97 @@ class_name GLTFVehicleHoverThruster
33extends Resource
44
55
6- ## The ratio of the maximum hover energy the hover thruster is currently using for propulsion.
6+ # Gimbal
7+ ## The maximum angle the hover thruster can gimbal or rotate in radians.
8+ @export_custom (PROPERTY_HINT_NONE , "suffix:rad" )
9+ var max_gimbal_radians : float = 0.0
10+ ## Optionally, you may also want to allow the gimbal to be adjusted based on linear input.
11+ ## For example, if the user wants to go forward, and the thruster points downward,
12+ ## we can gimbal the thruster slightly backward to help thrust forward.
713@export_range (0.0 , 1.0 , 0.01 )
8- var current_hover_ratio : float = 0.0
9- ## The ratio of the maximum gimbal angles the hover thruster is rotated to. The vector length may not be longer than 1.0.
10- @export var current_gimbal_ratio := Vector2 (0.0 , 0.0 )
14+ var linear_gimbal_adjust_ratio : float = 0.5
15+ ## The speed at which the gimbal angle changes, in radians per second. If negative, the angle changes instantly.
16+ @export_custom (PROPERTY_HINT_NONE , "suffix:rad/s" )
17+ var gimbal_radians_per_second : float = 1.0
18+ ## The ratio of the maximum gimbal angles the hover thruster is targeting to be rotated to. The vector length may not be longer than 1.0.
19+ @export var target_gimbal_ratio := Vector2 (0.0 , 0.0 )
20+
21+ # Hover Thrust
1122## The maximum hover energy in Newton-meters (N⋅m or kg⋅m²/s²) that the hover thruster can provide.
1223@export_custom (PROPERTY_HINT_NONE , "suffix:kg\u 22C5m\u 00B2/s\u 00B2 (N\u 22C5m)" )
1324var max_hover_energy : float = 0.0
14- ## The maximum angle the hover thruster can gimbal or rotate in radians.
15- @export_custom (PROPERTY_HINT_NONE , "suffix:rad" )
16- var max_gimbal : float = 0.0
25+ ## The speed at which the hover energy changes, in Newtons-meters per second. If negative, the force changes instantly.
26+ @export_custom (PROPERTY_HINT_NONE , "suffix:N\u 22C5m/s (kg\u 22C5m\u 00B2/s\u 00B3)" )
27+ var hover_energy_change_per_second : float = - 1.0
28+ ## The ratio of the maximum hover energy the hover thruster is targeting for propulsion.
29+ @export_range (0.0 , 1.0 , 0.01 )
30+ var target_hover_ratio : float = 0.0
1731
1832
1933static func from_node (thruster_node : VehicleHoverThruster3D ) -> GLTFVehicleHoverThruster :
2034 var ret := GLTFVehicleHoverThruster .new ()
21- ret .current_hover_ratio = thruster_node .current_hover_ratio
22- ret .current_gimbal_ratio = thruster_node .current_gimbal_ratio
35+ # Gimbal
36+ ret .max_gimbal_radians = thruster_node .max_gimbal_radians
37+ ret .linear_gimbal_adjust_ratio = thruster_node .linear_gimbal_adjust_ratio
38+ ret .gimbal_radians_per_second = thruster_node .gimbal_radians_per_second
39+ ret .target_gimbal_ratio = thruster_node .target_gimbal_ratio
40+ # Hover Thrust
2341 ret .max_hover_energy = thruster_node .max_hover_energy
24- ret .max_gimbal = thruster_node .max_gimbal
42+ ret .hover_energy_change_per_second = thruster_node .hover_energy_change_per_second
43+ ret .target_hover_ratio = thruster_node .target_hover_ratio
2544 return ret
2645
2746
2847func to_node () -> VehicleHoverThruster3D :
2948 var thruster_node := VehicleHoverThruster3D .new ()
30- thruster_node .current_hover_ratio = current_hover_ratio
31- thruster_node .current_gimbal_ratio = current_gimbal_ratio
49+ # Gimbal
50+ thruster_node .max_gimbal_radians = max_gimbal_radians
51+ thruster_node .linear_gimbal_adjust_ratio = linear_gimbal_adjust_ratio
52+ thruster_node .gimbal_radians_per_second = gimbal_radians_per_second
53+ thruster_node .target_gimbal_ratio = target_gimbal_ratio
54+ # Hover Thrust
3255 thruster_node .max_hover_energy = max_hover_energy
33- thruster_node .max_gimbal = max_gimbal
56+ thruster_node .hover_energy_change_per_second = hover_energy_change_per_second
57+ thruster_node .target_hover_ratio = target_hover_ratio
3458 return thruster_node
3559
3660
3761static func from_dictionary (dict : Dictionary ) -> GLTFVehicleHoverThruster :
3862 var ret := GLTFVehicleHoverThruster .new ()
39- if dict .has ("currentHoverRatio" ):
40- ret .current_force_ratio = dict ["currentHoverRatio" ]
41- if dict .has ("currentGimbalRatio" ):
42- ret .current_gimbal_ratio = dict ["currentGimbalRatio" ]
63+ # Gimbal
64+ if dict .has ("maxGimbal" ):
65+ ret .max_gimbal_radians = dict ["maxGimbal" ]
66+ if dict .has ("linearGimbalAdjustRatio" ):
67+ ret .linear_gimbal_adjust_ratio = dict ["linearGimbalAdjustRatio" ]
68+ if dict .has ("gimbalChangeRate" ):
69+ ret .gimbal_radians_per_second = dict ["gimbalChangeRate" ]
70+ if dict .has ("targetGimbalRatio" ):
71+ ret .target_gimbal_ratio = dict ["targetGimbalRatio" ]
72+ # Hover Thrust
4373 if dict .has ("maxHoverEnergy" ):
4474 ret .max_hover_energy = dict ["maxHoverEnergy" ]
45- if dict .has ("maxGimbal" ):
46- ret .max_gimbal = dict ["maxGimbal" ]
75+ if dict .has ("hoverEnergyChangeRate" ):
76+ ret .hover_energy_change_per_second = dict ["hoverEnergyChangeRate" ]
77+ if dict .has ("targetHoverRatio" ):
78+ ret .target_hover_ratio = dict ["targetHoverRatio" ]
4779 return ret
4880
4981
5082func to_dictionary () -> Dictionary :
5183 var ret : Dictionary = {}
84+ # Alphabetical order when converting to Dictionary.
85+ if gimbal_radians_per_second != 1.0 :
86+ ret ["gimbalChangeRate" ] = gimbal_radians_per_second
87+ if hover_energy_change_per_second != - 1.0 :
88+ ret ["hoverEnergyChangeRate" ] = hover_energy_change_per_second
89+ if linear_gimbal_adjust_ratio != 0.5 :
90+ ret ["linearGimbalAdjustRatio" ] = linear_gimbal_adjust_ratio
91+ if max_gimbal_radians != 0.0 :
92+ ret ["maxGimbal" ] = max_gimbal_radians
93+ # Always include maxHoverEnergy since it is a required property for hover thrusters.
5294 ret ["maxHoverEnergy" ] = max_hover_energy
53- if current_hover_ratio != 0.0 :
54- ret ["currentHoverRatio" ] = current_hover_ratio
55- if current_gimbal_ratio != Vector2 .ZERO :
56- ret ["currentGimbalRatio" ] = current_gimbal_ratio
57- if max_gimbal != 0.0 :
58- ret ["maxGimbal" ] = max_gimbal
95+ if target_gimbal_ratio != Vector2 .ZERO :
96+ ret ["targetGimbalRatio" ] = target_gimbal_ratio
97+ if target_hover_ratio != 0.0 :
98+ ret ["targetHoverRatio" ] = target_hover_ratio
5999 return ret
0 commit comments