- Spit BugMarker and BugMarkerDummy into two different classes so they can be more easily differentiated.
- Added a collision area to the marker to act as an info box in the future.
This commit is contained in:
parent
cc321675f0
commit
0ed55dd461
46
Scenes/bug_marker.gd
Normal file
46
Scenes/bug_marker.gd
Normal file
@ -0,0 +1,46 @@
|
||||
extends Node3D
|
||||
|
||||
enum BugStatus { NEUTRAL, UNRESOLVED, IN_PROGRESS, RESOLVED }
|
||||
@export var marker_status : BugStatus = BugStatus.NEUTRAL : set = __set_marker_status
|
||||
const NEUTRAL_COLOUR = Color.CORNFLOWER_BLUE
|
||||
const UNRESOLVED_COLOUR = Color(0.1, 0.0, 0.0)
|
||||
const IN_PROGRESS_COLOUR = Color(0.5, 0.5, 0.0)
|
||||
const RESOLVED_COLOUR = Color(0.0, 1.0, 0.0)
|
||||
|
||||
@export var enable_info : bool = true : set = set_info_enabled
|
||||
|
||||
@onready var __arrow : MeshInstance3D = $Arrow as MeshInstance3D
|
||||
@onready var __billboard : MeshInstance3D = $Billboard as MeshInstance3D
|
||||
@onready var __info_collider : Area3D = $Billboard/Info as Area3D
|
||||
var __arrow_material : ShaderMaterial
|
||||
var __billboard_material : ShaderMaterial
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if __arrow and __billboard:
|
||||
__arrow_material = __arrow.mesh.surface_get_material(0) as ShaderMaterial
|
||||
__billboard_material = __billboard.mesh.surface_get_material(0) as ShaderMaterial
|
||||
__set_marker_status(marker_status)
|
||||
|
||||
|
||||
func set_info_enabled(_enable:bool):
|
||||
__info_collider.collision_layer = 0xFFFFFFFF if _enable else 0x00000000
|
||||
|
||||
|
||||
func __set_marker_status(_status:BugStatus) -> void:
|
||||
if __arrow_material and __billboard_material:
|
||||
match _status:
|
||||
BugStatus.NEUTRAL:
|
||||
__arrow_material.set_shader_parameter("colour", NEUTRAL_COLOUR)
|
||||
__billboard_material.set_shader_parameter("colour", NEUTRAL_COLOUR)
|
||||
BugStatus.UNRESOLVED:
|
||||
__arrow_material.set_shader_parameter("colour", UNRESOLVED_COLOUR)
|
||||
__billboard_material.set_shader_parameter("colour", UNRESOLVED_COLOUR)
|
||||
BugStatus.IN_PROGRESS:
|
||||
__arrow_material.set_shader_parameter("colour", IN_PROGRESS_COLOUR)
|
||||
__billboard_material.set_shader_parameter("colour", IN_PROGRESS_COLOUR)
|
||||
BugStatus.RESOLVED:
|
||||
__arrow_material.set_shader_parameter("colour", RESOLVED_COLOUR)
|
||||
__billboard_material.set_shader_parameter("colour", RESOLVED_COLOUR)
|
||||
|
||||
marker_status = _status
|
||||
@ -1,5 +1,6 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://crr6cjploetps"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://crr6cjploetps"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/Bugbot/Scenes/bug_marker.gd" id="1_1adfi"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://dtvea38mlpfla" path="res://addons/Bugbot/Meshes/arrow.res" id="1_65xos"]
|
||||
[ext_resource type="Material" uid="uid://dkaq0ok73o5d4" path="res://addons/Bugbot/Materials/bug_marker_icon.material" id="3_px2dp"]
|
||||
|
||||
@ -8,7 +9,11 @@ material = ExtResource("3_px2dp")
|
||||
custom_aabb = AABB(-0.25, -0.25, -0.25, 0.5, 0.5, 0.5)
|
||||
size = Vector2(0.25, 0.25)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_t2p88"]
|
||||
radius = 0.125398
|
||||
|
||||
[node name="BugMarker" type="Node3D"]
|
||||
script = ExtResource("1_1adfi")
|
||||
|
||||
[node name="Arrow" type="MeshInstance3D" parent="."]
|
||||
cast_shadow = 0
|
||||
@ -18,3 +23,12 @@ mesh = ExtResource("1_65xos")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0)
|
||||
cast_shadow = 0
|
||||
mesh = SubResource("QuadMesh_dd1nc")
|
||||
|
||||
[node name="Info" type="Area3D" parent="Billboard" groups=["BugMarkerInfo"]]
|
||||
collision_layer = 4294967295
|
||||
collision_mask = 4294967295
|
||||
monitoring = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Billboard/Info"]
|
||||
shape = SubResource("SphereShape3D_t2p88")
|
||||
debug_color = Color(1, 0, 0, 1)
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
extends Node3D
|
||||
|
||||
enum BugStatus { UNRESOLVED, IN_PROGRESS, RESOLVED }
|
||||
@export var marker_status : BugStatus
|
||||
const UNRESOLVED_COLOUR = Color(0.1, 0.0, 0.0)
|
||||
const IN_PROGRESS_COLOUR = Color(0.5, 0.5, 0.0)
|
||||
const RESOLVED_COLOUR = Color(0.0, 0.1, 0.0)
|
||||
|
||||
@export var bug_marker : PackedScene
|
||||
@export var follow_node : Node3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var bug_marker_node : Node3D = bug_marker.instantiate() as Node3D
|
||||
add_child(bug_marker_node)
|
||||
bug_marker_node.enable_info = false
|
||||
|
||||
func _process(_delta:float) -> void:
|
||||
if not visible:
|
||||
position = Vector3(0.0, 0.0, 0.0)
|
||||
elif follow_node:
|
||||
global_position = follow_node.global_position
|
||||
|
||||
func set_rotation_to_normal(_normal:Vector3):
|
||||
func set_rotation_to_normal(_normal:Vector3) -> void:
|
||||
global_transform.basis.y = _normal
|
||||
global_transform.basis.x = global_transform.basis.z.cross(_normal)
|
||||
global_transform.basis = global_transform.basis.orthonormalized()
|
||||
|
||||
@ -57,7 +57,7 @@ extends CharacterBody3D
|
||||
|
||||
#region Onready
|
||||
@onready var __laser_beam : Node3D = $LaserBeamRoot as Node3D
|
||||
@onready var __bug_marker : Node3D = $BugMarker as Node3D
|
||||
@onready var __bug_marker_dummy : Node3D = $BugMarkerDummy as Node3D
|
||||
@onready var __movement_speed_change_timer : Timer = $MovementSpeedChangeTimer as Timer
|
||||
@onready var __exit_placement_timer : Timer = $ExitPlacementTimer as Timer
|
||||
@onready var __camera : Camera3D = $CollisionShape3D/Camera3D
|
||||
@ -216,14 +216,14 @@ func _ready() -> void:
|
||||
#endregion
|
||||
|
||||
func _process(_delta:float) -> void:
|
||||
_calculate_movement_speed()
|
||||
_calculate_rotation(_delta)
|
||||
_calculate_movement()
|
||||
_place_dummy_marker()
|
||||
__calculate_movement_speed()
|
||||
__calculate_rotation(_delta)
|
||||
__calculate_movement()
|
||||
__place_dummy_marker()
|
||||
|
||||
func _physics_process(_delta:float) -> void:
|
||||
_raycast_to_world()
|
||||
_calculate_button_presses()
|
||||
__raycast_to_world()
|
||||
__calculate_button_presses()
|
||||
move_and_slide()
|
||||
|
||||
|
||||
@ -231,7 +231,7 @@ static func instantiate(tree:SceneTree) -> void:
|
||||
tree.root.add_child(load("res://addons/Bugbot/Scenes/bugbot_player.tscn").instantiate() as CharacterBody3D)
|
||||
|
||||
|
||||
func _calculate_movement_speed() -> void:
|
||||
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.25
|
||||
@ -244,7 +244,7 @@ func _calculate_movement_speed() -> void:
|
||||
__movement_speed_change_timer.stop()
|
||||
__movement_speed = clampf(__movement_speed, 0.25, 100.0)
|
||||
|
||||
func _calculate_rotation(_delta:float) -> void:
|
||||
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
|
||||
@ -254,12 +254,12 @@ func _calculate_rotation(_delta:float) -> void:
|
||||
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:
|
||||
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:
|
||||
func __calculate_button_presses() -> void:
|
||||
if Input.is_action_just_pressed(&"bugbot_place_marker") and __raycast_collision:
|
||||
print("Marker placed at ", __raycast_collision["position"])
|
||||
|
||||
@ -267,13 +267,13 @@ func _calculate_button_presses() -> void:
|
||||
__exit_placement_timer.stop()
|
||||
elif Input.is_action_just_pressed(&"bugbot_exit_placement"):
|
||||
__exit_placement_timer.start()
|
||||
func _on_exit_placement_timer_timeout() -> void:
|
||||
func __on_exit_placement_timer_timeout() -> void:
|
||||
queue_free()
|
||||
|
||||
func _raycast_to_world():
|
||||
func __raycast_to_world():
|
||||
var space : PhysicsDirectSpaceState3D = get_world_3d().direct_space_state
|
||||
var query : PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(global_position, global_position - global_transform.basis.z * ray_length)
|
||||
query.collide_with_areas = false
|
||||
query.collide_with_areas = true
|
||||
query.collide_with_bodies = true
|
||||
query.exclude = [get_rid()]
|
||||
__raycast_collision = space.intersect_ray(query)
|
||||
@ -286,9 +286,9 @@ func _raycast_to_world():
|
||||
else:
|
||||
__laser_beam.visible = false
|
||||
|
||||
func _place_dummy_marker():
|
||||
func __place_dummy_marker():
|
||||
if __raycast_collision:
|
||||
__bug_marker.set_rotation_to_normal(__raycast_collision["normal"])
|
||||
__bug_marker.visible = true
|
||||
__bug_marker_dummy.set_rotation_to_normal(__raycast_collision["normal"])
|
||||
__bug_marker_dummy.visible = true
|
||||
else:
|
||||
__bug_marker.visible = false
|
||||
__bug_marker_dummy.visible = false
|
||||
|
||||
@ -93,8 +93,9 @@ joypad_movement_speed_down = ExtResource("31_t01c7")
|
||||
joypad_place_marker = ExtResource("32_q7vmk")
|
||||
joypad_exit_placement = ExtResource("33_lwr38")
|
||||
|
||||
[node name="BugMarker" parent="." node_paths=PackedStringArray("follow_node") instance=ExtResource("34_jyjbc")]
|
||||
[node name="BugMarkerDummy" type="Node3D" parent="." node_paths=PackedStringArray("follow_node")]
|
||||
script = ExtResource("35_ibing")
|
||||
bug_marker = ExtResource("34_jyjbc")
|
||||
follow_node = NodePath("../LaserBeamRoot/LaserGlare")
|
||||
|
||||
[node name="LaserBeamRoot" type="Node3D" parent="."]
|
||||
@ -127,4 +128,4 @@ one_shot = true
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="ExitPlacementTimer" to="." method="_on_exit_placement_timer_timeout" flags=6]
|
||||
[connection signal="timeout" from="ExitPlacementTimer" to="." method="__on_exit_placement_timer_timeout" flags=6]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user