Skip to content

Commit 1ab8753

Browse files
authored
Vehicles: Add braking, add change rate, rename current to target (#19)
1 parent e421986 commit 1ab8753

File tree

15 files changed

+498
-225
lines changed

15 files changed

+498
-225
lines changed

addons/omi_extensions/vehicle/gltf_vehicle_hover_thruster.gd

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,97 @@ class_name GLTFVehicleHoverThruster
33
extends 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\u22C5m\u00B2/s\u00B2 (N\u22C5m)")
1324
var 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\u22C5m/s (kg\u22C5m\u00B2/s\u00B3)")
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

1933
static 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

2847
func 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

3761
static 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

5082
func 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

addons/omi_extensions/vehicle/gltf_vehicle_thruster.gd

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,97 @@ class_name GLTFVehicleThruster
33
extends Resource
44

55

6-
## The ratio of the maximum thrust force the thruster is currently using for propulsion.
6+
# Gimbal
7+
## The maximum angle the 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_force_ratio: float = 0.0
9-
## The ratio of the maximum gimbal angles the 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.0
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 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+
# Thrust Force
1122
## The maximum thrust force in Newtons (kg⋅m/s²) that the thruster can provide.
1223
@export_custom(PROPERTY_HINT_NONE, "suffix:kg\u22C5m/s\u00B2 (N)")
1324
var max_force: float = 0.0
14-
## The maximum angle the 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 thruster force changes, in Newtons per second. If negative, the force changes instantly.
26+
@export_custom(PROPERTY_HINT_NONE, "suffix:N/s (kg\u22C5m/s\u00B3)")
27+
var force_change_per_second: float = -1.0
28+
## The ratio of the maximum thrust force the thruster is targeting for propulsion.
29+
@export_range(0.0, 1.0, 0.01)
30+
var target_force_ratio: float = 0.0
1731

1832

1933
static func from_node(thruster_node: VehicleThruster3D) -> GLTFVehicleThruster:
2034
var ret := GLTFVehicleThruster.new()
21-
ret.current_force_ratio = thruster_node.current_force_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+
# Thrust Force
2341
ret.max_force = thruster_node.max_force
24-
ret.max_gimbal = thruster_node.max_gimbal
42+
ret.force_change_per_second = thruster_node.force_change_per_second
43+
ret.target_force_ratio = thruster_node.target_force_ratio
2544
return ret
2645

2746

2847
func to_node() -> VehicleThruster3D:
2948
var thruster_node := VehicleThruster3D.new()
30-
thruster_node.current_force_ratio = current_force_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+
# Thrust Force
3255
thruster_node.max_force = max_force
33-
thruster_node.max_gimbal = max_gimbal
56+
thruster_node.force_change_per_second = force_change_per_second
57+
thruster_node.target_force_ratio = target_force_ratio
3458
return thruster_node
3559

3660

3761
static func from_dictionary(dict: Dictionary) -> GLTFVehicleThruster:
3862
var ret := GLTFVehicleThruster.new()
39-
if dict.has("currentForceRatio"):
40-
ret.current_force_ratio = dict["currentForceRatio"]
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+
# Thrust Force
4373
if dict.has("maxForce"):
4474
ret.max_force = dict["maxForce"]
45-
if dict.has("maxGimbal"):
46-
ret.max_gimbal = dict["maxGimbal"]
75+
if dict.has("forceChangeRate"):
76+
ret.force_change_per_second = dict["forceChangeRate"]
77+
if dict.has("targetForceRatio"):
78+
ret.target_force_ratio = dict["targetForceRatio"]
4779
return ret
4880

4981

5082
func to_dictionary() -> Dictionary:
5183
var ret: Dictionary = {}
84+
# Alphabetical order when converting to Dictionary.
85+
if force_change_per_second != -1.0:
86+
ret["forceChangeRate"] = force_change_per_second
87+
if gimbal_radians_per_second != 1.0:
88+
ret["gimbalChangeRate"] = gimbal_radians_per_second
89+
if linear_gimbal_adjust_ratio != 0.0:
90+
ret["linearGimbalAdjustRatio"] = linear_gimbal_adjust_ratio
91+
# Always include maxForce since it is a required property for thrusters.
5292
ret["maxForce"] = max_force
53-
if current_force_ratio != 0.0:
54-
ret["currentForceRatio"] = current_force_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
93+
if max_gimbal_radians != 0.0:
94+
ret["maxGimbal"] = max_gimbal_radians
95+
if target_force_ratio != 0.0:
96+
ret["targetForceRatio"] = target_force_ratio
97+
if target_gimbal_ratio != Vector2.ZERO:
98+
ret["targetGimbalRatio"] = target_gimbal_ratio
5999
return ret

0 commit comments

Comments
 (0)