Explorar el Código

:wrench: Separate lift and thrust for plane

DricomDragon hace 1 año
padre
commit
0b4513b5e6
Se han modificado 1 ficheros con 18 adiciones y 2 borrados
  1. 18 2
      first3d/component/entity/vehicles/plane/tiny_plane.gd

+ 18 - 2
first3d/component/entity/vehicles/plane/tiny_plane.gd

@@ -5,6 +5,7 @@ extends RigidBody3D
 @export var turn_to_torque: float = 2000.0
 @export var move_to_pitch: float = 4000.0
 @export var wing_resistance: float = 10.0
+@export var lift: float = 500.0
 
 var target_torque: float = 0.0
 var target_pitch: float = 0.0
@@ -16,7 +17,7 @@ var _current_commander: LocalInput = null
 
 func trigger_thrust(activate: bool) -> void:
 	if activate:
-		target_thrust = Vector3.FORWARD * thrust_power + Vector3.UP * thrust_power
+		target_thrust = Vector3.FORWARD * thrust_power
 	else:
 		target_thrust = Vector3.ZERO
 
@@ -42,6 +43,7 @@ func _physics_process(delta: float) -> void:
 	_apply_plane_rotation()
 	_apply_plane_thrust()
 	_apply_wing_resistance()
+	_apply_lift()
 
 
 func _apply_plane_rotation() -> void:
@@ -59,13 +61,27 @@ func _apply_wing_resistance() -> void:
 	var local_wing_force = Vector3.UP * -wing_resistance * vertical_speed
 	var wing_force = transform.basis * local_wing_force
 	if _current_commander != null:
-		print("- - -")
+		print("= = =")
 		print("Vertical speed : ", vertical_speed)
 		print("Wing force local :", local_wing_force)
 		print("Wing force : ", wing_force)
 	apply_central_force(wing_force)
 
 
+func _apply_lift() -> void:
+	var forward_speed = linear_velocity.dot(transform.basis * Vector3.FORWARD)
+	if forward_speed < 0.0 :
+		forward_speed = 0.0
+	var local_lift_force = Vector3.UP * lift * forward_speed
+	var lift_force = transform.basis * local_lift_force
+	if _current_commander != null:
+		print("- - -")
+		print("Forward speed : ", forward_speed)
+		print("Lift force local :", local_lift_force)
+		print("Lift force : ", lift_force)
+	apply_central_force(lift_force)
+
+
 func _on_dir_changed(dir: Vector2) -> void:
 	trigger_direction(dir)