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:
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()
func _input(event):
func _input(_event):
if Input.is_action_just_pressed("reset_drone"):
global_position = reset_point.global_position
global_rotation = Vector3.ZERO
@@ -94,18 +94,19 @@ func _input(event):
func _integrate_forces(state):
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:
throttle_speed = throttle_input * 100
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.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)
apply_central_force(global_transform.basis.y * 1 * thrust_factor) # Base thrust while props are idley spinning
@@ -114,17 +115,27 @@ func _integrate_forces(state):
anim_player.speed_scale = throttle_input * 4
anim_player.speed_scale = clampf(anim_player.speed_scale, 1.0, 4.0)
if yaw_input != 0:
rotate_object_local(Vector3.UP, yaw_input * rotation_speed) # Y axis rotation
if roll_input != 0:
rotate_object_local(Vector3.FORWARD, roll_input * rotation_speed) # Z axis rotation
if pitch_input != 0:
rotate_object_local(Vector3.RIGHT, pitch_input * rotation_speed) # X axis rotation
if yaw_input != 0:
rotate_object_local(Vector3.UP, yaw_input * rotation_speed) # Y axis rotation
if roll_input != 0:
rotate_object_local(Vector3.FORWARD, roll_input * rotation_speed) # Z axis rotation
if pitch_input != 0:
rotate_object_local(Vector3.RIGHT, pitch_input * rotation_speed) # X axis rotation
# Damping
if yaw_input == 0:
state.angular_velocity.y = lerp(state.angular_velocity.y, 0.0, 0.1)
if roll_input == 0:
state.angular_velocity.z = lerp(state.angular_velocity.z, 0.0, 0.1)
if pitch_input == 0:
state.angular_velocity.x = lerp(state.angular_velocity.x, 0.0, 0.1)
# Damping
if yaw_input == 0:
state.angular_velocity.y = lerp(state.angular_velocity.y, 0.0, 0.1)
if roll_input == 0:
state.angular_velocity.z = lerp(state.angular_velocity.z, 0.0, 0.1)
if pitch_input == 0:
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)