Browse Source

:wrench: Add plane controls

DricomDragon 1 year ago
parent
commit
479353b7d4

BIN
first3d/component/entity/ground/ground051.jpg


+ 34 - 0
first3d/component/entity/ground/ground051.jpg.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cgwafs6ukpm7y"
+path="res://.godot/imported/ground051.jpg-c3a76187b44b0be8f6c804fea4e92bca.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://component/entity/ground/ground051.jpg"
+dest_files=["res://.godot/imported/ground051.jpg-c3a76187b44b0be8f6c804fea4e92bca.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

+ 35 - 0
first3d/component/entity/plane/tiny_plane.gd

@@ -0,0 +1,35 @@
+class_name TinyPlane
+extends RigidBody3D
+
+@export var thrust_power: float = 14000.0
+@export var turn_to_torque: float = 2000.0
+@export var move_to_pitch: float = 2000.0
+
+var target_torque: float = 0.0
+var target_pitch: float = 0.0
+var target_rotation := Vector3.ZERO
+var target_thrust := Vector3.ZERO
+
+
+func trigger_thrust() -> void:
+	target_thrust = Vector3.FORWARD * thrust_power
+
+
+func trigger_direction(dir: Vector2) -> void:
+	print(dir)
+	target_torque = -dir.x * turn_to_torque
+	target_pitch = -dir.y * move_to_pitch
+
+
+func _physics_process(delta: float) -> void:
+	apply_torque(transform * Vector3(target_pitch, 0.0, target_torque))
+	apply_central_force(target_thrust)
+
+
+func _on_dir_changed(dir: Vector2) -> void:
+	trigger_direction(dir)
+
+
+func _on_main_action() -> void:
+	print("Thrust !")
+	trigger_thrust()

+ 3 - 1
first3d/component/entity/plane/tiny_plane.tscn

@@ -1,5 +1,6 @@
-[gd_scene load_steps=4 format=3 uid="uid://dao17ylietgyl"]
+[gd_scene load_steps=5 format=3 uid="uid://dao17ylietgyl"]
 
+[ext_resource type="Script" path="res://component/entity/plane/tiny_plane.gd" id="1_q8t3a"]
 [ext_resource type="PackedScene" uid="uid://bnopi1rerk2hw" path="res://component/entity/plane/TinyPlane.glb" id="1_umuah"]
 
 [sub_resource type="BoxShape3D" id="BoxShape3D_08gtm"]
@@ -12,6 +13,7 @@ size = Vector3(5.20238, 0.197845, 1)
 collision_layer = 8
 collision_mask = 3
 mass = 750.0
+script = ExtResource("1_q8t3a")
 
 [node name="TinyPlane" parent="." instance=ExtResource("1_umuah")]
 

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

@@ -51,7 +51,15 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.2632, -0.5, -7.95074)
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.53697, 1.42774, -11.1883)
 
 [node name="TinyPlane" parent="." instance=ExtResource("4_tbpfc")]
-transform = Transform3D(0.559549, 0.630013, -0.538506, -0.747682, 0.664057, 0, 0.357599, 0.402631, 0.842622, -20.3652, 13.6463, -19.5506)
+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="CameraPlane" type="Camera3D" parent="TinyPlane"]
+transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.81859, 8.36889)
+current = true
+
+[node name="Control" parent="TinyPlane" instance=ExtResource("2_0i5t8")]
 
 [connection signal="dir_changed" from="MainWalker/Control" to="MainWalker" method="_on_dir_changed"]
 [connection signal="main_action" from="MainWalker/Control" to="MainWalker" method="_on_main_action"]
+[connection signal="dir_changed" from="TinyPlane/Control" to="TinyPlane" method="_on_dir_changed"]
+[connection signal="main_action" from="TinyPlane/Control" to="TinyPlane" method="_on_main_action"]