Single rotation and force

This commit is contained in:
Gary Steven Keough 2025-02-03 21:00:37 -05:00
parent ccd94eed31
commit d520c17010
3 changed files with 27 additions and 32 deletions

View File

@ -10,10 +10,10 @@ 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.5
@export var max_speed: float = 100.0
@export var rotation_speed: float = 0.15
@export var max_speed: float = 20.0
@export var max_rotation_speed: float = 15.0
@export var camera_tilt_angle: float = 0.0
@export var thrust_factor: float = 1.0
@export_category("Node References")
@export var camera: Camera3D
@export var anim_player: AnimationPlayer
@ -35,22 +35,6 @@ func _process(_delta):
handle_arming()
func handle_throttle(throttle_input: float):
if using_joy_controller:
if throttle_input > 0:
throttle_speed = throttle_input * 100
apply_central_force(global_transform.basis.y * throttle_speed)
# 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, -max_speed, max_speed)
linear_velocity.z = clampf(linear_velocity.z, -max_speed, max_speed)
func handle_arming():
if !armed:
if !animation_initalized:
@ -78,6 +62,8 @@ func _on_flip_over_timeout():
can_flip = true
input_suggestion_label.text = "press A to flip drone"
input_suggestion_label.show()
else:
input_suggestion_label.hide()
func _handle_drone_flipping():
@ -85,6 +71,8 @@ func _handle_drone_flipping():
global_rotation = Vector3.ZERO
input_suggestion_label.hide()
can_flip = false
else:
input_suggestion_label.hide()
func _physics_process(_delta): # Still needed for other physics
@ -103,14 +91,25 @@ func _input(event):
angular_velocity = Vector3.ZERO
func _integrate_forces(state): # Use _integrate_forces for RigidBody3D control
if armed and GameManager.game_started: # Only apply controls when armed and when the game has started
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 throttle_input > 0:
throttle_speed = throttle_input * 100
apply_central_force(global_transform.basis.y * throttle_speed * thrust_factor)
linear_velocity.x = clampf(linear_velocity.x, -max_speed, max_speed)
linear_velocity.y = clampf(linear_velocity.y, -100.0, max_speed)
linear_velocity.z = clampf(linear_velocity.z, -max_speed, max_speed)
handle_throttle(throttle_input) # Throttle handled here
# 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)
if yaw_input != 0:
rotate_object_local(Vector3.UP, yaw_input * rotation_speed) # Y axis rotation
@ -126,8 +125,3 @@ func _integrate_forces(state): # Use _integrate_forces for RigidBody3D control
state.angular_velocity.z = lerp(state.angular_velocity.z, 0.0, 0.05)
if pitch_input == 0:
state.angular_velocity.x = lerp(state.angular_velocity.x, 0.0, 0.05)
# 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

@ -1071,10 +1071,10 @@ shadow_mesh = SubResource("ArrayMesh_oy56j")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_pkxv0"]
shader = ExtResource("9_66bpw")
shader_parameter/curvature = 0.0
shader_parameter/skip = 0.05
shader_parameter/image_flicker = 0.06
shader_parameter/skip = 0.01
shader_parameter/image_flicker = 0.01
shader_parameter/vignette_flicker_speed = 0.0
shader_parameter/vignette_strength = 1.0
shader_parameter/vignette_strength = 0.0
shader_parameter/small_scanlines_speed = 1.0
shader_parameter/small_scanlines_proximity = 1.0
shader_parameter/small_scanlines_opacity = 0.31
@ -1087,11 +1087,11 @@ shader_parameter/noise_texture = ExtResource("10_ylv8e")
[node name="Drone" type="RigidBody3D" node_paths=PackedStringArray("camera", "anim_player", "flip_over_detection_ray", "flip_over_timer", "input_suggestion_label")]
collision_layer = 2
collision_mask = 7
mass = 0.6
physics_material_override = SubResource("PhysicsMaterial_kpx62")
can_sleep = false
continuous_cd = true
script = ExtResource("1_de83i")
rotation_speed = 0.08
max_speed = 10.0
camera = NodePath("VisualComponets/CameraPivot/Camera3D")
anim_player = NodePath("AnimationPlayer")
flip_over_detection_ray = NodePath("FlipOverDetectionRay")
@ -1321,6 +1321,7 @@ script = ExtResource("9_8eblv")
[node name="CanvasLayer" type="CanvasLayer" parent="VisualComponets/CameraPivot/Camera3D"]
[node name="VHSVFX" type="Control" parent="VisualComponets/CameraPivot/Camera3D/CanvasLayer"]
visible = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0

Binary file not shown.