Rescaled maps and reworked drone code

Rescaled maps and reworked drone code to support fpv remote and joy controller with a menu switch
This commit is contained in:
Gary Steven Keough 2025-02-15 22:31:27 -05:00
parent bad3fe6f1e
commit 6b85034a30
11 changed files with 133 additions and 824 deletions

View File

@ -84,7 +84,7 @@ func _physics_process(_delta): # Still needed for other physics
_handle_drone_flipping() _handle_drone_flipping()
func _input(event): func _input(_event):
if Input.is_action_just_pressed("reset_drone"): if Input.is_action_just_pressed("reset_drone"):
global_position = reset_point.global_position global_position = reset_point.global_position
global_rotation = Vector3.ZERO global_rotation = Vector3.ZERO
@ -94,18 +94,19 @@ func _input(event):
func _integrate_forces(state): func _integrate_forces(state):
if armed and GameManager.game_started: if armed and GameManager.game_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")
if using_joy_controller:
if GameManager.controller_mode == "JoyController":
var yaw_input = Input.get_axis("joy_yaw_right", "joy_yaw_left")
var roll_input = Input.get_axis("joy_roll_right", "joy_roll_left")
var pitch_input = Input.get_axis("joy_pitch_backward", "joy_pitch_forward")
var throttle_input = Input.get_axis("joy_throttle_down", "joy_throttle_up")
if throttle_input > 0: if throttle_input > 0:
throttle_speed = throttle_input * 100 throttle_speed = throttle_input * 100
apply_central_force(global_transform.basis.y * throttle_curve.sample((throttle_speed-1)/99) * thrust_factor) apply_central_force(global_transform.basis.y * throttle_curve.sample((throttle_speed-1)/99) * thrust_factor)
linear_velocity.x = clampf(linear_velocity.x, -max_speed, max_speed) linear_velocity.x = clampf(linear_velocity.x, -max_speed, max_speed)
linear_velocity.y = clampf(linear_velocity.y, -max_speed*1.5, max_speed) linear_velocity.y = clampf(linear_velocity.y, -max_speed*2.0, max_speed)
linear_velocity.z = clampf(linear_velocity.z, -max_speed, max_speed) linear_velocity.z = clampf(linear_velocity.z, -max_speed, max_speed)
apply_central_force(global_transform.basis.y * 1 * thrust_factor) # Base thrust while props are idley spinning apply_central_force(global_transform.basis.y * 1 * thrust_factor) # Base thrust while props are idley spinning
@ -128,3 +129,13 @@ func _integrate_forces(state):
state.angular_velocity.z = lerp(state.angular_velocity.z, 0.0, 0.1) state.angular_velocity.z = lerp(state.angular_velocity.z, 0.0, 0.1)
if pitch_input == 0: if pitch_input == 0:
state.angular_velocity.x = lerp(state.angular_velocity.x, 0.0, 0.1) state.angular_velocity.x = lerp(state.angular_velocity.x, 0.0, 0.1)
if GameManager.controller_mode == "FPVRemote":
var yaw_input = Input.get_axis("fpv_yaw_right", "fpv_yaw_left")
var roll_input = Input.get_axis("fpv_roll_right", "fpv_roll_left")
var pitch_input = Input.get_axis("fpv_pitch_backward", "fpv_pitch_forward")
var throttle_input = Input.get_axis("fpv_throttle_down", "fpv_throttle_up")
if throttle_input > -1:
var scaled_throttle_input = (throttle_input + 1)/2 # scales throttle from (-1 to 1) to (0 to 1)
print(scaled_throttle_input)

File diff suppressed because one or more lines are too long

View File

@ -1,17 +1,15 @@
[gd_scene load_steps=6 format=3 uid="uid://5ht1wfq36328"] [gd_scene load_steps=5 format=3 uid="uid://5ht1wfq36328"]
[ext_resource type="Shader" uid="uid://c66rr4lq10okt" path="res://core/resources/shaders/ground_repetition.tres" id="1_ggga8"]
[ext_resource type="PackedScene" uid="uid://bsbckpn0bymwl" path="res://assets/models/level_building/scene.gltf" id="2_orjp2"] [ext_resource type="PackedScene" uid="uid://bsbckpn0bymwl" path="res://assets/models/level_building/scene.gltf" id="2_orjp2"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_6xxch"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_6xxch"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qof1c"] [sub_resource type="PlaneMesh" id="PlaneMesh_qporw"]
render_priority = 0 size = Vector2(500, 500)
shader = ExtResource("1_ggga8")
[sub_resource type="PlaneMesh" id="PlaneMesh_1obgk"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wl7tr"]
material = SubResource("ShaderMaterial_qof1c") albedo_color = Color(0.240374, 0.221831, 0.221831, 1)
size = Vector2(200, 200) metallic_specular = 0.0
[node name="RunDownBuilding" type="Node3D"] [node name="RunDownBuilding" type="Node3D"]
@ -21,7 +19,8 @@ size = Vector2(200, 200)
shape = SubResource("WorldBoundaryShape3D_6xxch") shape = SubResource("WorldBoundaryShape3D_6xxch")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"] [node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"]
mesh = SubResource("PlaneMesh_1obgk") mesh = SubResource("PlaneMesh_qporw")
surface_material_override/0 = SubResource("StandardMaterial3D_wl7tr")
[node name="Sketchfab_Scene" parent="." instance=ExtResource("2_orjp2")] [node name="Sketchfab_Scene" parent="." instance=ExtResource("2_orjp2")]
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, -4.57199, 0) transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, -12.243, 0)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=3 uid="uid://deah8x3tnm045"] [gd_scene load_steps=15 format=3 uid="uid://deah8x3tnm045"]
[ext_resource type="Texture2D" uid="uid://b3ecco3iykmlc" path="res://assets/textures/overcast_soil_puresky_4k.hdr" id="1_4mr0e"] [ext_resource type="Texture2D" uid="uid://b3ecco3iykmlc" path="res://assets/textures/overcast_soil_puresky_4k.hdr" id="1_4mr0e"]
[ext_resource type="PackedScene" uid="uid://dwvmna8qc0vb4" path="res://core/drone/drone.tscn" id="2_orkyq"] [ext_resource type="PackedScene" uid="uid://dwvmna8qc0vb4" path="res://core/drone/drone.tscn" id="2_orkyq"]
@ -29,6 +29,12 @@ bake_resolution = 1
_data = [Vector2(0, 90), 0.0, -220.055, 0, 0, Vector2(0.0753138, 59.5526), -282.238, -282.238, 0, 0, Vector2(0.449093, 7.72959), -32.7953, -32.7953, 0, 0, Vector2(0.994421, 1), -7.74656, 0.0, 0, 0] _data = [Vector2(0, 90), 0.0, -220.055, 0, 0, Vector2(0.0753138, 59.5526), -282.238, -282.238, 0, 0, Vector2(0.449093, 7.72959), -32.7953, -32.7953, 0, 0, Vector2(0.994421, 1), -7.74656, 0.0, 0, 0]
point_count = 4 point_count = 4
[sub_resource type="LabelSettings" id="LabelSettings_rjteo"]
shadow_color = Color(0, 0, 0, 0.611765)
[sub_resource type="LabelSettings" id="LabelSettings_ymk35"]
shadow_color = Color(0, 0, 0, 0.611765)
[node name="Main" type="Node3D"] [node name="Main" type="Node3D"]
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
@ -46,6 +52,7 @@ environment = SubResource("Environment_ruppb")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.017014, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.017014, 0)
[node name="Drone" parent="ResetPoint" node_paths=PackedStringArray("reset_point") instance=ExtResource("2_orkyq")] [node name="Drone" parent="ResetPoint" node_paths=PackedStringArray("reset_point") instance=ExtResource("2_orkyq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -20.7659, 0, -31.913)
reset_point = NodePath("..") reset_point = NodePath("..")
[node name="LOSView" type="Node3D" parent="." node_paths=PackedStringArray("drone", "child_camera")] [node name="LOSView" type="Node3D" parent="." node_paths=PackedStringArray("drone", "child_camera")]
@ -64,7 +71,7 @@ script = ExtResource("3_sec6q")
process_mode = 3 process_mode = 3
layer = 2 layer = 2
[node name="MainMenu" type="Control" parent="CanvasLayer" node_paths=PackedStringArray("start_button", "quit_button")] [node name="MainMenu" type="Control" parent="CanvasLayer" node_paths=PackedStringArray("start_button", "quit_button", "controller_mode_button", "joy_controller_label", "fpv_remote_label")]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -74,6 +81,9 @@ grow_vertical = 2
script = ExtResource("4_bknjq") script = ExtResource("4_bknjq")
start_button = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/StartButton") start_button = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/StartButton")
quit_button = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/QuitButton") quit_button = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/QuitButton")
controller_mode_button = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/ControllerModeButton")
joy_controller_label = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/JoyControllerLabel")
fpv_remote_label = NodePath("HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/FPVRemoteLabel")
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/MainMenu"] [node name="TextureRect" type="TextureRect" parent="CanvasLayer/MainMenu"]
layout_mode = 1 layout_mode = 1
@ -100,7 +110,7 @@ alignment = 1
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer"] [node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_right = 150 theme_override_constants/margin_right = 65
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer"]
layout_mode = 2 layout_mode = 2
@ -109,13 +119,36 @@ alignment = 1
[node name="StartButton" type="Button" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] [node name="StartButton" type="Button" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
focus_neighbor_bottom = NodePath("../QuitButton") focus_neighbor_bottom = NodePath("../HBoxContainer/ControllerModeButton")
theme_override_font_sizes/font_size = 50 theme_override_font_sizes/font_size = 50
text = "START" text = "START"
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
alignment = 1
[node name="JoyControllerLabel" type="Label" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
self_modulate = Color(0, 1, 0, 1)
layout_mode = 2
text = "JOY CONTROLLER"
label_settings = SubResource("LabelSettings_rjteo")
[node name="ControllerModeButton" type="CheckButton" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
focus_neighbor_top = NodePath("../../StartButton")
focus_neighbor_bottom = NodePath("../../QuitButton")
alignment = 1
icon_alignment = 1
[node name="FPVRemoteLabel" type="Label" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer"]
self_modulate = Color(0.498039, 0.498039, 0.498039, 1)
layout_mode = 2
text = "FPV REMOTE"
label_settings = SubResource("LabelSettings_ymk35")
[node name="QuitButton" type="Button" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] [node name="QuitButton" type="Button" parent="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
focus_neighbor_top = NodePath("../StartButton") focus_neighbor_top = NodePath("../HBoxContainer/ControllerModeButton")
theme_override_font_sizes/font_size = 50 theme_override_font_sizes/font_size = 50
text = "QUIT" text = "QUIT"
@ -181,3 +214,5 @@ theme_override_font_sizes/font_size = 25
text = "QUIT" text = "QUIT"
[node name="TestLevel" parent="." instance=ExtResource("4_oqdxa")] [node name="TestLevel" parent="." instance=ExtResource("4_oqdxa")]
[connection signal="toggled" from="CanvasLayer/MainMenu/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer/HBoxContainer/ControllerModeButton" to="CanvasLayer/MainMenu" method="_on_controller_mode_button_toggled"]

View File

@ -28,7 +28,7 @@ function = 1
input_name = "uv" input_name = "uv"
[sub_resource type="VisualShaderNodeFloatConstant" id="VisualShaderNodeFloatConstant_ygstf"] [sub_resource type="VisualShaderNodeFloatConstant" id="VisualShaderNodeFloatConstant_ygstf"]
constant = 50.0 constant = 100.0
[sub_resource type="FastNoiseLite" id="FastNoiseLite_5ogwx"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_5ogwx"]
noise_type = 2 noise_type = 2
@ -93,7 +93,7 @@ void fragment() {
// FloatConstant:25 // FloatConstant:25
float n_out25p0 = 50.000000; float n_out25p0 = 100.000000;
// UVFunc:23 // UVFunc:23
@ -178,6 +178,7 @@ void fragment() {
} }
" "
graph_offset = Vector2(-1734.9, 193.248)
nodes/fragment/0/position = Vector2(1000, 220) nodes/fragment/0/position = Vector2(1000, 220)
nodes/fragment/19/node = SubResource("VisualShaderNodeVec2Constant_0gqw2") nodes/fragment/19/node = SubResource("VisualShaderNodeVec2Constant_0gqw2")
nodes/fragment/19/position = Vector2(-2120, 580) nodes/fragment/19/position = Vector2(-2120, 580)

View File

@ -5,9 +5,10 @@ extends Node3D
@export var current_camera: int = 0 @export var current_camera: int = 0
@export var game_started: bool = false @export var game_started: bool = false
@export var is_paused: bool = false @export var is_paused: bool = false
@export var controller_mode: String = "JoyController"
func _process(delta): func _process(_delta):
if camera_array.size() != 0 and Input.is_action_just_released("change_camera_view"): if camera_array.size() != 0 and Input.is_action_just_released("change_camera_view"):
current_camera += 1 current_camera += 1
if current_camera <= camera_array.size() - 1: if current_camera <= camera_array.size() - 1:

View File

@ -11,7 +11,7 @@ func _ready():
child_camera = get_child(0) child_camera = get_child(0)
func _physics_process(delta): func _physics_process(_delta):
look_at(drone.global_position) look_at(drone.global_position)
dist_to_drone = global_position.distance_to(drone.global_position) dist_to_drone = global_position.distance_to(drone.global_position)

View File

@ -2,6 +2,9 @@ extends Control
@export var start_button: Button @export var start_button: Button
@export var quit_button: Button @export var quit_button: Button
@export var controller_mode_button: CheckButton
@export var joy_controller_label: Label
@export var fpv_remote_label: Label
func _ready(): func _ready():
@ -23,3 +26,14 @@ func _on_quit_button_pressed():
func _on_visibility_changed() -> void: func _on_visibility_changed() -> void:
if visible: if visible:
start_button.grab_focus() start_button.grab_focus()
func _on_controller_mode_button_toggled(toggled_on):
if toggled_on:
GameManager.controller_mode = "FPVRemote"
joy_controller_label.self_modulate = Color(0.5, 0.5, 0.5, 1.0)
fpv_remote_label.self_modulate = Color(0.0, 1.0, 0.0, 1.0)
elif !toggled_on:
GameManager.controller_mode = "JoyController"
joy_controller_label.self_modulate = Color(0.0, 1.0, 0.0, 1.0)
fpv_remote_label.self_modulate = Color(0.5, 0.5, 0.5, 1.0)

View File

@ -20,7 +20,7 @@ func _on_quit_button_pressed():
get_tree().quit() get_tree().quit()
func _input(event: InputEvent) -> void: func _input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("start") and !GameManager.is_paused and GameManager.game_started: if Input.is_action_just_pressed("start") and !GameManager.is_paused and GameManager.game_started:
_toggle_pause_state(true) _toggle_pause_state(true)
elif Input.is_action_just_pressed("start") and GameManager.is_paused: elif Input.is_action_just_pressed("start") and GameManager.is_paused:

View File

@ -1,5 +1,5 @@
extends Label extends Label
func _process(delta): func _process(_delta):
text = str(Engine.get_frames_per_second()) + " FPS" text = str(Engine.get_frames_per_second()) + " FPS"

View File

@ -46,42 +46,42 @@ arm={
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null) "events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
] ]
} }
throttle_up={ joy_throttle_up={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
] ]
} }
roll_right={ joy_roll_right={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
] ]
} }
yaw_right={ joy_yaw_right={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
] ]
} }
pitch_forward={ joy_pitch_forward={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
] ]
} }
throttle_down={ joy_throttle_down={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
] ]
} }
yaw_left={ joy_yaw_left={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
] ]
} }
roll_left={ joy_roll_left={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
] ]
} }
pitch_backward={ joy_pitch_backward={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
] ]