Selaa lähdekoodia

:tada: First attempt to implement wing resistance

DricomDragon 1 vuosi sitten
vanhempi
commit
28115fec88

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

@@ -4,7 +4,7 @@ extends RigidBody3D
 @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 lift: float = 10000.0
+@export var wing_resistance: float = 10.0
 
 var target_torque: float = 0.0
 var target_pitch: float = 0.0
@@ -16,7 +16,7 @@ var _current_commander: LocalInput = null
 
 func trigger_thrust(activate: bool) -> void:
 	if activate:
-		target_thrust = Vector3.FORWARD * thrust_power + Vector3.UP * lift
+		target_thrust = Vector3.FORWARD * thrust_power + Vector3.UP * thrust_power
 	else:
 		target_thrust = Vector3.ZERO
 
@@ -41,6 +41,7 @@ func get_out() -> void:
 func _physics_process(delta: float) -> void:
 	_apply_plane_rotation()
 	_apply_plane_thrust()
+	_apply_wing_resistance()
 
 
 func _apply_plane_rotation() -> void:
@@ -53,6 +54,18 @@ func _apply_plane_thrust() -> void:
 	apply_central_force(force)
 
 
+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
+	if _current_commander != null:
+		print("- - -")
+		print("Vertical speed : ", vertical_speed)
+		print("Wing force local :", local_wing_force)
+		print("Wing force : ", wing_force)
+	apply_central_force(wing_force)
+
+
 func _on_dir_changed(dir: Vector2) -> void:
 	trigger_direction(dir)
 

+ 1 - 1
first3d/run/levels/infinite_level.tscn

@@ -70,7 +70,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -17.1773, 0, -8.17952)
 transform = Transform3D(0.477312, 0.527326, -0.702923, -0.741391, 0.671074, 0, 0.471713, 0.521141, 0.711266, -76.6685, 15.7672, 53.8067)
 
 [node name="TinyPlane2" parent="." instance=ExtResource("4_tbpfc")]
-transform = Transform3D(-0.589079, -0.650805, -0.478999, -0.741391, 0.671074, 1.34747e-08, 0.321443, 0.355125, -0.877816, -10.5959, 3.94108, -17.5095)
+transform = Transform3D(-0.153959, -0.170091, -0.973328, -0.741391, 0.671074, 4.00299e-08, 0.653174, 0.721616, -0.229421, -10.5959, 3.94108, -17.5095)
 
 [node name="Jeep1" parent="." instance=ExtResource("6_nnvc5")]
 transform = Transform3D(-0.0560131, 0.291646, 0.954885, 0, 0.956386, -0.292105, -0.99843, -0.0163617, -0.0535702, -16.454, 0.747562, 8.03092)