Functional prototype

This commit is contained in:
2025-02-02 23:55:33 -05:00
parent 1eb408b1c8
commit 7b9a0ea032
15 changed files with 9341 additions and 56 deletions

View File

@@ -10,10 +10,9 @@ extends RigidBody3D
@export var armed: bool = false
@export var can_flip: bool = false
@export var throttle_speed: float = 0.0
@export var rotation_speed: float = 0.05 # Adjust as needed
@export var acceleration: float = 0.5 # Adjust as needed
@export var max_speed: float = 1.0 # Adjust as needed
@export var max_rotation_speed: float = 5.0 # Adjust as needed
@export var rotation_speed: float = 0.5
@export var max_speed: float = 100.0
@export var max_rotation_speed: float = 15.0
@export var camera_tilt_angle: float = 0.0
@export_category("Node References")
@export var camera: Camera3D
@@ -21,6 +20,7 @@ extends RigidBody3D
@export var flip_over_detection_ray: RayCast3D
@export var flip_over_timer: Timer
@export var input_suggestion_label: Label
@export var reset_point: Marker3D
var animation_initalized: bool = false
var using_joy_controller: bool = true
@@ -40,15 +40,13 @@ func handle_throttle(throttle_input: float):
if throttle_input > 0:
throttle_speed = throttle_input * 100
apply_central_force(global_transform.basis.y * throttle_speed)
elif throttle_input <= 0.05: # Adjust this value if needed
apply_central_force(global_transform.basis.y * 1) # Minimum thrust
# Speed scale adjusted for animation
anim_player.speed_scale = throttle_input * 4
anim_player.speed_scale = clampf(anim_player.speed_scale, 1.0, 4.0)
linear_velocity.x = clampf(linear_velocity.x, -max_speed, max_speed)
linear_velocity.y = clampf(linear_velocity.y, -100.0, max_speed) # Keep vertical clamping
linear_velocity.y = clampf(linear_velocity.y, -max_speed, max_speed)
linear_velocity.z = clampf(linear_velocity.z, -max_speed, max_speed)
@@ -89,7 +87,7 @@ func _handle_drone_flipping():
can_flip = false
func _physics_process(_delta): # Still needed for other physics
func _physics_process(_delta): # Still needed for other physics
if flip_over_detection_ray.is_colliding() and flip_over_detection_ray.get_collider().is_in_group("Ground"):
_start_flip_over_timer()
@@ -97,14 +95,22 @@ func _physics_process(_delta): # Still needed for other physics
_handle_drone_flipping()
func _input(event):
if Input.is_action_just_pressed("reset_drone"):
global_position = reset_point.global_position
global_rotation = Vector3.ZERO
linear_velocity = Vector3.ZERO
angular_velocity = Vector3.ZERO
func _integrate_forces(state): # Use _integrate_forces for RigidBody3D control
if armed: # Only apply controls when armed
if armed and GameManager.game_started: # Only apply controls when armed and when the game has started
var yaw_input = Input.get_axis("yaw_right", "yaw_left")
var roll_input = Input.get_axis("roll_right", "roll_left")
var pitch_input = Input.get_axis("pitch_backward", "pitch_forward")
var throttle_input = Input.get_axis("throttle_down", "throttle_up")
handle_throttle(throttle_input) # Throttle still handled here
handle_throttle(throttle_input) # Throttle handled here
if yaw_input != 0:
rotate_object_local(Vector3.UP, yaw_input * rotation_speed) # Y axis rotation
@@ -113,7 +119,7 @@ func _integrate_forces(state): # Use _integrate_forces for RigidBody3D control
if pitch_input != 0:
rotate_object_local(Vector3.RIGHT, pitch_input * rotation_speed) # X axis rotation
# Damping (Important! Still needed):
# Damping
if yaw_input == 0:
state.angular_velocity.y = lerp(state.angular_velocity.y, 0.0, 0.05)
if roll_input == 0:
@@ -121,7 +127,7 @@ func _integrate_forces(state): # Use _integrate_forces for RigidBody3D control
if pitch_input == 0:
state.angular_velocity.x = lerp(state.angular_velocity.x, 0.0, 0.05)
# Clamp the angular velocity (optional, but good practice):
# Clamp the angular velocity
state.angular_velocity.y = clampf(state.angular_velocity.y, -max_rotation_speed, max_rotation_speed)
state.angular_velocity.z = clampf(state.angular_velocity.z, -max_rotation_speed, max_rotation_speed)
state.angular_velocity.x = clampf(state.angular_velocity.x, -max_rotation_speed, max_rotation_speed)

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=103 format=4 uid="uid://dwvmna8qc0vb4"]
[gd_scene load_steps=104 format=4 uid="uid://dwvmna8qc0vb4"]
[ext_resource type="Script" path="res://core/drone/drone.gd" id="1_de83i"]
[ext_resource type="Material" uid="uid://d0gkxc5fuh354" path="res://core/resources/materials/black_carbon_fiber.tres" id="2_phv8m"]
@@ -11,6 +11,7 @@
[ext_resource type="Script" path="res://core/scripts/camera_3d.gd" id="9_8eblv"]
[ext_resource type="Shader" path="res://core/resources/shaders/vhs.gdshader" id="9_66bpw"]
[ext_resource type="Texture2D" uid="uid://bv7klk2tmhya2" path="res://assets/textures/rgba-noise-medium.png" id="10_ylv8e"]
[ext_resource type="PackedScene" uid="uid://c6w6axh4l4w8d" path="res://core/tools/fps_label.tscn" id="12_u7iaa"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_kpx62"]
bounce = 0.1
@@ -1366,3 +1367,18 @@ theme_override_constants/margin_bottom = 40
visible = false
layout_mode = 2
text = "press A to flip drone"
[node name="HBoxContainer" type="HBoxContainer" parent="VisualComponets/CameraPivot/Camera3D/CanvasLayer/HUD"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
alignment = 2
[node name="VBoxContainer" type="VBoxContainer" parent="VisualComponets/CameraPivot/Camera3D/CanvasLayer/HUD/HBoxContainer"]
layout_mode = 2
[node name="MarginContainer" parent="VisualComponets/CameraPivot/Camera3D/CanvasLayer/HUD/HBoxContainer/VBoxContainer" instance=ExtResource("12_u7iaa")]
layout_mode = 2