Parcourir la source

:wrench: Create foil resistance

In order to prevent lateral drift.
DricomDragon il y a 4 jours
Parent
commit
4a04ced029
1 fichiers modifiés avec 17 ajouts et 13 suppressions
  1. 17 13
      godot/component/entity/vehicles/biplan/biplan.gd

+ 17 - 13
godot/component/entity/vehicles/biplan/biplan.gd

@@ -3,17 +3,20 @@ extends SeatedVehicle
 
 const PLANE_FORWARD := Vector3.BACK # z increases when moving forward
 
-@export var thrust_power: float = 10000.0
-@export var turn_to_torque: float = 2000.0
-@export var move_to_pitch: float = 4000.0
-@export var wing_resistance: float = 5000.0
-@export var lift: float = 100.0
+@export var thrust_power: float = 3500.0
+@export var turn_to_torque: float = 1000.0
+@export var move_to_pitch: float = 2000.0
+@export var wing_resistance: float = 2500.0
+@export var foil_resistance: float = 250.0
+@export var lift: float = 50.0
 
 var target_torque: float = 0.0
 var target_pitch: float = 0.0
 var target_rotation := Vector3.ZERO
 var target_thrust := Vector3.ZERO
 
+@onready var HorizontalFoil : Node3D = $HorizontalFoil
+
 
 func trigger_thrust(activate: bool) -> void:
 	if activate:
@@ -41,6 +44,7 @@ func _physics_process(_delta) -> void:
 		return
 
 	_apply_wing_resistance()
+	_apply_foil_resistance()
 	_apply_lift()
 
 
@@ -58,23 +62,23 @@ func _apply_wing_resistance() -> void:
 	var vertical_speed = linear_velocity.dot(transform.basis * Vector3.UP)
 	var local_wing_force = Vector3.UP * -wing_resistance * vertical_speed
 	var wing_force = transform.basis * local_wing_force
-	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_foil_resistance() -> void:
+	var foil_position : Vector3 = HorizontalFoil.get_position()
+	var horizontal_speed = linear_velocity.dot(transform.basis * Vector3.RIGHT)
+	var local_foil_force = Vector3.RIGHT * -foil_resistance * horizontal_speed
+	var foil_force = transform.basis * local_foil_force
+	apply_force(foil_force, foil_position)
+
+
 func _apply_lift() -> void:
 	var forward_speed = linear_velocity.dot(transform.basis * PLANE_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
-	print("- - -")
-	print("Forward speed : ", forward_speed)
-	print("Lift force local :", local_lift_force)
-	print("Lift force : ", lift_force)
 	apply_central_force(lift_force)