From d370c1f0a30e4552eb40218811be2ec3e1ec7fbe Mon Sep 17 00:00:00 2001 From: Jamie Greunbaum Date: Tue, 14 May 2024 03:03:31 -0400 Subject: [PATCH] - Added a raycast and laser that points to the location of a bug. - Added the ability to exit bug placement when holding the exit button for a length of time. --- Meshes/laser_beam.res | Bin 0 -> 912 bytes Scenes/bugbot_player.gd | 85 ++++++++++++++++++++++--------- Scenes/bugbot_player.tscn | 103 ++++++++++++++++++++++++++------------ 3 files changed, 132 insertions(+), 56 deletions(-) create mode 100644 Meshes/laser_beam.res diff --git a/Meshes/laser_beam.res b/Meshes/laser_beam.res new file mode 100644 index 0000000000000000000000000000000000000000..be516eed9e34725af3006ed1d0e2f71317ef80fd GIT binary patch literal 912 zcmV;B18@9NQ$s@n000005C8zE2LJ$g0{{RhwJ-f(s0MW#0G8{0Hc(HJ4lq;v%*@Qp z6y7psHVKDqwh>95y*J~Ngb=wmvXUjW>Gx=5FpWoVEcfUjfdmprAdOOL0Bitm0Q@YA zCT3~EhMTjGEf3suO}9)+Jtz}%F0E9`e+BUyOr4qhq+xx%7) zP&UrG$iM_|=|(P9{jg*f?x~z;yF?3{HC@Pr%YC#uI$_&bDQ;gXq`f$ym$H^ElrQB( zmtGHZ@I2TuEGR58MJZJfHs-T>K+4{67E%|B7=i2M1HRO-2Rbgfvr_hXjNd zO9>$m5S$zS(|9xVp~G=}=tzrcVW)sVKxklQX@PUEbeQB*$d4vmW@$>;E+Tm%lIK!7 za888FHC2j&cn)iRkV4&TMDSkPoaz>UtEh3QF$ftVnVF;@mBugvLYS(m9ugqcHA#&_ zLo>65+1cNRy8Q8Wym;}C^(Nld4*Ao2Mo+q9qv^lxyRJ+e#0*5RL2!H@F*H8kstv$Z zfd_Fw0vCkzt2qga?N7Wg497jbd8ROOgg2z*v7`(e;Nn{CI2&t-@WX}DLyCy}$Nd~Z zy<*XS1W7Q0Q|Zn?4(|)D3K$g3V}8MregMjYpq#72(LtgvD!m1b;?NLFc`DB`Hj*KqjSkz-3zgOOlB=mjZ;Q(q4vxa zXpzYV0Zfl-wTbjpZ@u6MDg1&Gk~tU+{Xei!q3v`r)TX^nf5;*VWWo6vTnl&-iaC3Q m^)*qk8T*$S6wSlu#tCzwnT@Abrjy63$~DU2%WfS~Q$s@>uCE3F literal 0 HcmV?d00001 diff --git a/Scenes/bugbot_player.gd b/Scenes/bugbot_player.gd index e0d200a..fc70362 100644 --- a/Scenes/bugbot_player.gd +++ b/Scenes/bugbot_player.gd @@ -21,14 +21,12 @@ extends CharacterBody3D @export var keyboard_exit_placement : InputEventKey @export_subgroup("Mouse") -@export var mouse_tilt_up : InputEventMouseMotion -@export var mouse_tilt_down : InputEventMouseMotion -@export var mouse_pan_left : InputEventMouseMotion -@export var mouse_pan_right : InputEventMouseMotion - @export var mouse_movement_speed_up : InputEventMouseButton @export var mouse_movement_speed_down : InputEventMouseButton +@export var mouse_place_marker : InputEventMouseButton +@export var mouse_exit_placement : InputEventMouseButton + @export_subgroup("Joystick") @export var joypad_move_forward : InputEventJoypadMotion @export var joypad_move_backward : InputEventJoypadMotion @@ -48,7 +46,10 @@ extends CharacterBody3D @export var joypad_place_marker : InputEventJoypadButton @export var joypad_exit_placement : InputEventJoypadButton -@onready var input_change_timer : Timer = $InputChangeTimer +@onready var raycast : RayCast3D = $RayCast3D +@onready var laser_beam : Node3D = $LaserBeamRoot +@onready var movement_speed_change_timer : Timer = $MovementSpeedChangeTimer +@onready var exit_placement_timer : Timer = $ExitPlacementTimer var movement_speed : float = 5.0 @@ -100,6 +101,16 @@ func _enter_tree() -> void: InputMap.action_add_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down) InputMap.action_add_event(&"bugbot_movement_speed_down", mouse_movement_speed_down) InputMap.action_add_event(&"bugbot_movement_speed_down", joypad_movement_speed_down) + + InputMap.add_action(&"bugbot_place_marker") + InputMap.action_add_event(&"bugbot_place_marker", keyboard_place_marker) + InputMap.action_add_event(&"bugbot_place_marker", mouse_place_marker) + InputMap.action_add_event(&"bugbot_place_marker", joypad_place_marker) + + InputMap.add_action(&"bugbot_exit_placement") + InputMap.action_add_event(&"bugbot_exit_placement", keyboard_exit_placement) + InputMap.action_add_event(&"bugbot_exit_placement", mouse_exit_placement) + InputMap.action_add_event(&"bugbot_exit_placement", joypad_exit_placement) func _exit_tree() -> void: InputMap.action_erase_event(&"bugbot_move_forward", keyboard_move_forward) @@ -127,8 +138,39 @@ func _exit_tree() -> void: func _process(_delta:float) -> void: - _calculate_movement_speed() + if raycast.is_colliding(): + var collision_point : Vector3 = raycast.get_collision_point() + var distance_to_collision : float = global_position.distance_to(collision_point) + laser_beam.scale.z = distance_to_collision + laser_beam.look_at(collision_point) + laser_beam.visible = true + else: + laser_beam.visible = false + _calculate_movement_speed() + _calculate_rotation(_delta) + _calculate_movement() + + _calculate_button_presses() + +func _physics_process(_delta:float) -> void: + move_and_slide() + + +func _calculate_movement_speed() -> void: + if Input.is_action_pressed(&"bugbot_movement_speed_down") or Input.is_action_just_pressed(&"bugbot_movement_speed_down"): + if movement_speed_change_timer.is_stopped(): + movement_speed /= 1.2 + movement_speed_change_timer.start() + elif Input.is_action_pressed(&"bugbot_movement_speed_up") or Input.is_action_just_pressed(&"bugbot_movement_speed_up"): + if movement_speed_change_timer.is_stopped(): + movement_speed *= 1.2 + movement_speed_change_timer.start() + else: + movement_speed_change_timer.stop() + movement_speed = clampf(movement_speed, 0.25, 50.0) + +func _calculate_rotation(_delta:float) -> void: var rotation_velocity : Vector2 = Vector2( Input.get_axis(&"bugbot_tilt_down", &"bugbot_tilt_up"), Input.get_axis(&"bugbot_pan_right", &"bugbot_pan_left")) * 2.5 @@ -137,24 +179,19 @@ func _process(_delta:float) -> void: rotation_velocity.y += mouse_velocity.x * -0.0025 rotation.x = clampf(rotation.x + (rotation_velocity.x * _delta), -PI/2.0 + 0.0001, PI/2.0 - 0.0001) rotation.y += rotation_velocity.y * _delta - + +func _calculate_movement() -> void: var movement_vector_lateral : Vector2 = Input.get_vector(&"bugbot_move_left", &"bugbot_move_right", &"bugbot_move_forward", &"bugbot_move_backward") var movement_azimuth : float = Input.get_axis(&"bugbot_move_down", &"bugbot_move_up") velocity = transform.basis * Vector3(movement_vector_lateral.x, movement_azimuth, movement_vector_lateral.y) * movement_speed + +func _calculate_button_presses() -> void: + if Input.is_action_just_pressed(&"bugbot_place_marker") and raycast.is_colliding(): + print("Marker placed at ", raycast.get_collision_point()) -func _physics_process(_delta:float) -> void: - move_and_slide() - - -func _calculate_movement_speed(): - if Input.is_action_pressed(&"bugbot_movement_speed_down") or Input.is_action_just_pressed(&"bugbot_movement_speed_down"): - if input_change_timer.is_stopped(): - movement_speed /= 1.2 - input_change_timer.start() - elif Input.is_action_pressed(&"bugbot_movement_speed_up") or Input.is_action_just_pressed(&"bugbot_movement_speed_up"): - if input_change_timer.is_stopped(): - movement_speed *= 1.2 - input_change_timer.start() - else: - input_change_timer.stop() - movement_speed = clampf(movement_speed, 0.25, 50.0) + if Input.is_action_just_released(&"bugbot_exit_placement"): + exit_placement_timer.stop() + elif Input.is_action_just_pressed(&"bugbot_exit_placement"): + exit_placement_timer.start() +func _on_exit_placement_timer_timeout() -> void: + queue_free() diff --git a/Scenes/bugbot_player.tscn b/Scenes/bugbot_player.tscn index 5aa5f77..6797d7f 100644 --- a/Scenes/bugbot_player.tscn +++ b/Scenes/bugbot_player.tscn @@ -1,36 +1,53 @@ -[gd_scene load_steps=33 format=3 uid="uid://dvgain3s4xa4r"] +[gd_scene load_steps=37 format=3 uid="uid://dvgain3s4xa4r"] [ext_resource type="Script" path="res://addons/bugbot/Scenes/bugbot_player.gd" id="1_0w1su"] -[ext_resource type="InputEventKey" uid="uid://di5q6d4wt12et" path="res://addons/bugbot/Inputs/Keyboard/move_forward.res" id="2_4xsm8"] -[ext_resource type="InputEventJoypadMotion" uid="uid://dvfivmwsi3fua" path="res://addons/bugbot/Inputs/Joystick/move_forward.res" id="2_ib0o8"] -[ext_resource type="InputEventJoypadMotion" uid="uid://bslmd7psb8fxj" path="res://addons/bugbot/Inputs/Joystick/move_backward.res" id="3_f3wgw"] -[ext_resource type="InputEventKey" uid="uid://dq5h1k8r7qc8e" path="res://addons/bugbot/Inputs/Keyboard/move_backward.res" id="3_t3c17"] -[ext_resource type="InputEventJoypadMotion" uid="uid://81iwh4jprsvg" path="res://addons/bugbot/Inputs/Joystick/move_left.res" id="4_fjxg2"] -[ext_resource type="InputEventKey" uid="uid://cll7mf8252ygb" path="res://addons/bugbot/Inputs/Keyboard/move_left.res" id="4_jrc8e"] -[ext_resource type="InputEventJoypadMotion" uid="uid://dgxujj8rm83ms" path="res://addons/bugbot/Inputs/Joystick/move_right.res" id="5_l00mx"] -[ext_resource type="InputEventKey" uid="uid://7bd7qoj1d3if" path="res://addons/bugbot/Inputs/Keyboard/move_right.res" id="5_xjrx0"] -[ext_resource type="InputEventKey" uid="uid://cxms65i1ajl84" path="res://addons/bugbot/Inputs/Keyboard/move_up.res" id="6_8kaqn"] -[ext_resource type="InputEventJoypadMotion" uid="uid://dxeo2l03mfag8" path="res://addons/bugbot/Inputs/Joystick/move_up.res" id="6_rw5gh"] -[ext_resource type="InputEventJoypadMotion" uid="uid://clplko5i2fjfg" path="res://addons/bugbot/Inputs/Joystick/move_down.res" id="7_asamw"] -[ext_resource type="InputEventKey" uid="uid://bv3rhr5nb770i" path="res://addons/bugbot/Inputs/Keyboard/move_down.res" id="7_awoo8"] -[ext_resource type="InputEventKey" uid="uid://cll5bqmbaide7" path="res://addons/bugbot/Inputs/Keyboard/place_marker.res" id="8_4no4m"] -[ext_resource type="InputEventJoypadButton" uid="uid://bc2q8kry856bq" path="res://addons/bugbot/Inputs/Joystick/place_marker.res" id="8_a8xs2"] -[ext_resource type="InputEventKey" uid="uid://b2368i5gabwe4" path="res://addons/bugbot/Inputs/Keyboard/tilt_up.res" id="8_itpt0"] -[ext_resource type="InputEventKey" uid="uid://sj40g81evgwp" path="res://addons/bugbot/Inputs/Keyboard/exit_placement.res" id="9_62i1v"] -[ext_resource type="InputEventJoypadButton" uid="uid://8tu5a8nlxgsj" path="res://addons/bugbot/Inputs/Joystick/exit_placement.res" id="9_64pej"] -[ext_resource type="InputEventKey" uid="uid://c778uo6xncv8" path="res://addons/bugbot/Inputs/Keyboard/tilt_down.res" id="9_idsj8"] -[ext_resource type="InputEventKey" uid="uid://b1jle0pubrtd5" path="res://addons/bugbot/Inputs/Keyboard/pan_left.res" id="10_7s4mn"] -[ext_resource type="InputEventKey" uid="uid://b7cakmjeiw6ww" path="res://addons/bugbot/Inputs/Keyboard/pan_right.res" id="11_7rtm5"] -[ext_resource type="InputEventKey" uid="uid://dg3voh0vrvttt" path="res://addons/bugbot/Inputs/Keyboard/speed_up.res" id="12_vqtae"] -[ext_resource type="InputEventKey" uid="uid://bsuakshn5uf5q" path="res://addons/bugbot/Inputs/Keyboard/speed_down.res" id="13_umxce"] -[ext_resource type="InputEventMouseButton" uid="uid://cri3v62of5r8q" path="res://addons/bugbot/Inputs/Mouse/speed_up.res" id="14_kyasb"] -[ext_resource type="InputEventMouseButton" uid="uid://xjdbqccjrdv6" path="res://addons/bugbot/Inputs/Mouse/speed_down.res" id="15_64bwo"] -[ext_resource type="InputEventJoypadMotion" uid="uid://1r555cp6na2j" path="res://addons/bugbot/Inputs/Joystick/tilt_up.res" id="16_037yq"] -[ext_resource type="InputEventJoypadMotion" uid="uid://ceq7h0j71rdbj" path="res://addons/bugbot/Inputs/Joystick/tilt_down.res" id="17_v3d4v"] -[ext_resource type="InputEventJoypadMotion" uid="uid://cwekj3w1gwt6s" path="res://addons/bugbot/Inputs/Joystick/pan_left.res" id="18_t1llp"] -[ext_resource type="InputEventJoypadMotion" uid="uid://coqroda2l61k4" path="res://addons/bugbot/Inputs/Joystick/pan_right.res" id="19_boyi2"] -[ext_resource type="InputEventJoypadButton" uid="uid://busy4w43xnjni" path="res://addons/bugbot/Inputs/Joystick/speed_up.res" id="28_j37cx"] -[ext_resource type="InputEventJoypadButton" uid="uid://biuae513qxxf2" path="res://addons/bugbot/Inputs/Joystick/speed_down.res" id="29_ywpxq"] +[ext_resource type="InputEventKey" uid="uid://di5q6d4wt12et" path="res://addons/Bugbot/Inputs/Keyboard/move_forward.res" id="2_4xsm8"] +[ext_resource type="InputEventJoypadMotion" uid="uid://dvfivmwsi3fua" path="res://addons/Bugbot/Inputs/Joystick/move_forward.res" id="2_ib0o8"] +[ext_resource type="InputEventJoypadMotion" uid="uid://bslmd7psb8fxj" path="res://addons/Bugbot/Inputs/Joystick/move_backward.res" id="3_f3wgw"] +[ext_resource type="InputEventKey" uid="uid://dq5h1k8r7qc8e" path="res://addons/Bugbot/Inputs/Keyboard/move_backward.res" id="3_t3c17"] +[ext_resource type="InputEventJoypadMotion" uid="uid://81iwh4jprsvg" path="res://addons/Bugbot/Inputs/Joystick/move_left.res" id="4_fjxg2"] +[ext_resource type="InputEventKey" uid="uid://cll7mf8252ygb" path="res://addons/Bugbot/Inputs/Keyboard/move_left.res" id="4_jrc8e"] +[ext_resource type="InputEventJoypadMotion" uid="uid://dgxujj8rm83ms" path="res://addons/Bugbot/Inputs/Joystick/move_right.res" id="5_l00mx"] +[ext_resource type="InputEventKey" uid="uid://7bd7qoj1d3if" path="res://addons/Bugbot/Inputs/Keyboard/move_right.res" id="5_xjrx0"] +[ext_resource type="InputEventKey" uid="uid://cxms65i1ajl84" path="res://addons/Bugbot/Inputs/Keyboard/move_up.res" id="6_8kaqn"] +[ext_resource type="InputEventJoypadMotion" uid="uid://dxeo2l03mfag8" path="res://addons/Bugbot/Inputs/Joystick/move_up.res" id="6_rw5gh"] +[ext_resource type="InputEventJoypadMotion" uid="uid://clplko5i2fjfg" path="res://addons/Bugbot/Inputs/Joystick/move_down.res" id="7_asamw"] +[ext_resource type="InputEventKey" uid="uid://bv3rhr5nb770i" path="res://addons/Bugbot/Inputs/Keyboard/move_down.res" id="7_awoo8"] +[ext_resource type="InputEventKey" uid="uid://cll5bqmbaide7" path="res://addons/Bugbot/Inputs/Keyboard/place_marker.res" id="8_4no4m"] +[ext_resource type="InputEventJoypadButton" uid="uid://bc2q8kry856bq" path="res://addons/Bugbot/Inputs/Joystick/place_marker.res" id="8_a8xs2"] +[ext_resource type="InputEventKey" uid="uid://b2368i5gabwe4" path="res://addons/Bugbot/Inputs/Keyboard/tilt_up.res" id="8_itpt0"] +[ext_resource type="InputEventKey" uid="uid://sj40g81evgwp" path="res://addons/Bugbot/Inputs/Keyboard/exit_placement.res" id="9_62i1v"] +[ext_resource type="InputEventJoypadButton" uid="uid://8tu5a8nlxgsj" path="res://addons/Bugbot/Inputs/Joystick/exit_placement.res" id="9_64pej"] +[ext_resource type="InputEventKey" uid="uid://c778uo6xncv8" path="res://addons/Bugbot/Inputs/Keyboard/tilt_down.res" id="9_idsj8"] +[ext_resource type="InputEventKey" uid="uid://b1jle0pubrtd5" path="res://addons/Bugbot/Inputs/Keyboard/pan_left.res" id="10_7s4mn"] +[ext_resource type="InputEventKey" uid="uid://b7cakmjeiw6ww" path="res://addons/Bugbot/Inputs/Keyboard/pan_right.res" id="11_7rtm5"] +[ext_resource type="InputEventKey" uid="uid://dg3voh0vrvttt" path="res://addons/Bugbot/Inputs/Keyboard/speed_up.res" id="12_vqtae"] +[ext_resource type="InputEventKey" uid="uid://bsuakshn5uf5q" path="res://addons/Bugbot/Inputs/Keyboard/speed_down.res" id="13_umxce"] +[ext_resource type="InputEventMouseButton" uid="uid://cri3v62of5r8q" path="res://addons/Bugbot/Inputs/Mouse/speed_up.res" id="14_kyasb"] +[ext_resource type="InputEventMouseButton" uid="uid://xjdbqccjrdv6" path="res://addons/Bugbot/Inputs/Mouse/speed_down.res" id="15_64bwo"] +[ext_resource type="InputEventJoypadMotion" uid="uid://1r555cp6na2j" path="res://addons/Bugbot/Inputs/Joystick/tilt_up.res" id="16_037yq"] +[ext_resource type="InputEventJoypadMotion" uid="uid://ceq7h0j71rdbj" path="res://addons/Bugbot/Inputs/Joystick/tilt_down.res" id="17_v3d4v"] +[ext_resource type="InputEventMouseButton" uid="uid://pbqtdh1qlcmv" path="res://addons/Bugbot/Inputs/Mouse/place_marker.res" id="18_j04wu"] +[ext_resource type="InputEventJoypadMotion" uid="uid://cwekj3w1gwt6s" path="res://addons/Bugbot/Inputs/Joystick/pan_left.res" id="18_t1llp"] +[ext_resource type="InputEventJoypadMotion" uid="uid://coqroda2l61k4" path="res://addons/Bugbot/Inputs/Joystick/pan_right.res" id="19_boyi2"] +[ext_resource type="InputEventMouseButton" uid="uid://dfwl72js5v3nw" path="res://addons/Bugbot/Inputs/Mouse/exit_placement.res" id="19_frcom"] +[ext_resource type="InputEventJoypadButton" uid="uid://busy4w43xnjni" path="res://addons/Bugbot/Inputs/Joystick/speed_up.res" id="28_j37cx"] +[ext_resource type="InputEventJoypadButton" uid="uid://biuae513qxxf2" path="res://addons/Bugbot/Inputs/Joystick/speed_down.res" id="29_ywpxq"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2mp42"] +cull_mode = 2 +shading_mode = 0 +specular_mode = 2 +disable_ambient_light = true +disable_fog = true +albedo_color = Color(10, 1, 1, 1) +disable_receive_shadows = true + +[sub_resource type="CylinderMesh" id="CylinderMesh_ts4fq"] +material = SubResource("StandardMaterial3D_2mp42") +top_radius = 0.005 +bottom_radius = 0.005 +height = 1.0 [sub_resource type="SphereShape3D" id="SphereShape3D_6gwao"] @@ -59,6 +76,8 @@ keyboard_place_marker = ExtResource("8_4no4m") keyboard_exit_placement = ExtResource("9_62i1v") mouse_movement_speed_up = ExtResource("14_kyasb") mouse_movement_speed_down = ExtResource("15_64bwo") +mouse_place_marker = ExtResource("18_j04wu") +mouse_exit_placement = ExtResource("19_frcom") joypad_move_forward = ExtResource("2_ib0o8") joypad_move_backward = ExtResource("3_f3wgw") joypad_move_left = ExtResource("4_fjxg2") @@ -74,12 +93,32 @@ joypad_movement_speed_down = ExtResource("29_ywpxq") joypad_place_marker = ExtResource("8_a8xs2") joypad_exit_placement = ExtResource("9_64pej") +[node name="RayCast3D" type="RayCast3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0) +target_position = Vector3(0, -25, 0) +collision_mask = 4294967295 + +[node name="LaserBeamRoot" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, -0.5, 0) + +[node name="LaserBeam" type="MeshInstance3D" parent="LaserBeamRoot"] +transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, -0.5) +cast_shadow = 0 +mesh = SubResource("CylinderMesh_ts4fq") +skeleton = NodePath("../..") + [node name="CollisionShape3D" type="CollisionShape3D" parent="."] shape = SubResource("SphereShape3D_6gwao") debug_color = Color(0.5, 0.7, 1, 1) [node name="Camera3D" type="Camera3D" parent="CollisionShape3D"] -[node name="InputChangeTimer" type="Timer" parent="."] +[node name="MovementSpeedChangeTimer" type="Timer" parent="."] wait_time = 0.05 one_shot = true + +[node name="ExitPlacementTimer" type="Timer" parent="."] +wait_time = 0.5 +one_shot = true + +[connection signal="timeout" from="ExitPlacementTimer" to="." method="_on_exit_placement_timer_timeout" flags=6]