Bugbot camera now automatically places itself in the same spot as the active game camera, and also takes on its properties.
This commit is contained in:
parent
48ef7bf0b6
commit
c7e53c5dea
@ -49,20 +49,25 @@ extends CharacterBody3D
|
|||||||
@onready var laser_beam : Node3D = $LaserBeamRoot as Node3D
|
@onready var laser_beam : Node3D = $LaserBeamRoot as Node3D
|
||||||
@onready var movement_speed_change_timer : Timer = $MovementSpeedChangeTimer as Timer
|
@onready var movement_speed_change_timer : Timer = $MovementSpeedChangeTimer as Timer
|
||||||
@onready var exit_placement_timer : Timer = $ExitPlacementTimer as Timer
|
@onready var exit_placement_timer : Timer = $ExitPlacementTimer as Timer
|
||||||
|
@onready var camera : Camera3D = $CollisionShape3D/Camera3D
|
||||||
|
|
||||||
var movement_speed : float = 5.0
|
var movement_speed : float = 5.0
|
||||||
|
|
||||||
|
var stored_camera : Camera3D
|
||||||
var stored_mouse_mode : int = Input.MOUSE_MODE_CAPTURED
|
var stored_mouse_mode : int = Input.MOUSE_MODE_CAPTURED
|
||||||
var stored_pause_status : bool = false
|
var stored_pause_status : bool = false
|
||||||
var raycast_collision : Dictionary
|
var raycast_collision : Dictionary
|
||||||
|
|
||||||
|
|
||||||
|
#region Initialisation
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
|
stored_camera = get_viewport().get_camera_3d()
|
||||||
stored_pause_status = get_tree().paused
|
stored_pause_status = get_tree().paused
|
||||||
get_tree().paused = true
|
get_tree().paused = true
|
||||||
stored_mouse_mode = Input.mouse_mode
|
stored_mouse_mode = Input.mouse_mode
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||||
|
|
||||||
|
#region Movement Configuration
|
||||||
InputMap.add_action(&"bugbot_move_forward", 0.1)
|
InputMap.add_action(&"bugbot_move_forward", 0.1)
|
||||||
InputMap.action_add_event(&"bugbot_move_forward", keyboard_move_forward)
|
InputMap.action_add_event(&"bugbot_move_forward", keyboard_move_forward)
|
||||||
InputMap.action_add_event(&"bugbot_move_forward", joypad_move_forward)
|
InputMap.action_add_event(&"bugbot_move_forward", joypad_move_forward)
|
||||||
@ -81,7 +86,9 @@ func _enter_tree() -> void:
|
|||||||
InputMap.add_action(&"bugbot_move_up", 0.1)
|
InputMap.add_action(&"bugbot_move_up", 0.1)
|
||||||
InputMap.action_add_event(&"bugbot_move_up", keyboard_move_up)
|
InputMap.action_add_event(&"bugbot_move_up", keyboard_move_up)
|
||||||
InputMap.action_add_event(&"bugbot_move_up", joypad_move_up)
|
InputMap.action_add_event(&"bugbot_move_up", joypad_move_up)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Camera Configuration
|
||||||
InputMap.add_action(&"bugbot_tilt_up", 0.1)
|
InputMap.add_action(&"bugbot_tilt_up", 0.1)
|
||||||
InputMap.action_add_event(&"bugbot_tilt_up", keyboard_tilt_up)
|
InputMap.action_add_event(&"bugbot_tilt_up", keyboard_tilt_up)
|
||||||
InputMap.action_add_event(&"bugbot_tilt_up", joypad_tilt_up)
|
InputMap.action_add_event(&"bugbot_tilt_up", joypad_tilt_up)
|
||||||
@ -94,7 +101,9 @@ func _enter_tree() -> void:
|
|||||||
InputMap.add_action(&"bugbot_pan_right", 0.1)
|
InputMap.add_action(&"bugbot_pan_right", 0.1)
|
||||||
InputMap.action_add_event(&"bugbot_pan_right", keyboard_pan_right)
|
InputMap.action_add_event(&"bugbot_pan_right", keyboard_pan_right)
|
||||||
InputMap.action_add_event(&"bugbot_pan_right", joypad_pan_right)
|
InputMap.action_add_event(&"bugbot_pan_right", joypad_pan_right)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Speed Configuration
|
||||||
InputMap.add_action(&"bugbot_movement_speed_up")
|
InputMap.add_action(&"bugbot_movement_speed_up")
|
||||||
InputMap.action_add_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
InputMap.action_add_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
||||||
InputMap.action_add_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
InputMap.action_add_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
||||||
@ -103,7 +112,9 @@ func _enter_tree() -> void:
|
|||||||
InputMap.action_add_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down)
|
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", mouse_movement_speed_down)
|
||||||
InputMap.action_add_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
InputMap.action_add_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Marker Placement Configuration
|
||||||
InputMap.add_action(&"bugbot_place_marker")
|
InputMap.add_action(&"bugbot_place_marker")
|
||||||
InputMap.action_add_event(&"bugbot_place_marker", keyboard_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", mouse_place_marker)
|
||||||
@ -113,8 +124,10 @@ func _enter_tree() -> void:
|
|||||||
InputMap.action_add_event(&"bugbot_exit_placement", keyboard_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", mouse_exit_placement)
|
||||||
InputMap.action_add_event(&"bugbot_exit_placement", joypad_exit_placement)
|
InputMap.action_add_event(&"bugbot_exit_placement", joypad_exit_placement)
|
||||||
|
#endregion
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
|
#region Movement Deconfiguration
|
||||||
InputMap.action_erase_event(&"bugbot_move_forward", keyboard_move_forward)
|
InputMap.action_erase_event(&"bugbot_move_forward", keyboard_move_forward)
|
||||||
InputMap.action_erase_event(&"bugbot_move_forward", joypad_move_forward)
|
InputMap.action_erase_event(&"bugbot_move_forward", joypad_move_forward)
|
||||||
InputMap.action_erase_event(&"bugbot_move_backward", keyboard_move_backward)
|
InputMap.action_erase_event(&"bugbot_move_backward", keyboard_move_backward)
|
||||||
@ -127,17 +140,67 @@ func _exit_tree() -> void:
|
|||||||
InputMap.action_erase_event(&"bugbot_move_down", joypad_move_down)
|
InputMap.action_erase_event(&"bugbot_move_down", joypad_move_down)
|
||||||
InputMap.action_erase_event(&"bugbot_move_up", keyboard_move_up)
|
InputMap.action_erase_event(&"bugbot_move_up", keyboard_move_up)
|
||||||
InputMap.action_erase_event(&"bugbot_move_up", joypad_move_up)
|
InputMap.action_erase_event(&"bugbot_move_up", joypad_move_up)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Camera Deconfiguration
|
||||||
|
InputMap.action_add_event(&"bugbot_tilt_up", keyboard_tilt_up)
|
||||||
|
InputMap.action_add_event(&"bugbot_tilt_up", joypad_tilt_up)
|
||||||
|
InputMap.action_add_event(&"bugbot_tilt_down", keyboard_tilt_down)
|
||||||
|
InputMap.action_add_event(&"bugbot_tilt_down", joypad_tilt_down)
|
||||||
|
InputMap.action_add_event(&"bugbot_pan_left", keyboard_pan_left)
|
||||||
|
InputMap.action_add_event(&"bugbot_pan_left", joypad_pan_left)
|
||||||
|
InputMap.action_add_event(&"bugbot_pan_right", keyboard_pan_right)
|
||||||
|
InputMap.action_add_event(&"bugbot_pan_right", joypad_pan_right)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Speed Deconfiguration
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_up", joypad_movement_speed_up)
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", joypad_movement_speed_up)
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down)
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down)
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_down", mouse_movement_speed_down)
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", mouse_movement_speed_down)
|
||||||
InputMap.action_erase_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Marker Placement Deconfiguration
|
||||||
|
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)
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Action Removal
|
||||||
|
InputMap.erase_action(&"bugbot_move_forward")
|
||||||
|
InputMap.erase_action(&"bugbot_move_backward")
|
||||||
|
InputMap.erase_action(&"bugbot_move_left")
|
||||||
|
InputMap.erase_action(&"bugbot_move_right")
|
||||||
|
InputMap.erase_action(&"bugbot_move_down")
|
||||||
|
InputMap.erase_action(&"bugbot_move_up")
|
||||||
|
InputMap.erase_action(&"bugbot_tilt_up")
|
||||||
|
InputMap.erase_action(&"bugbot_tilt_down")
|
||||||
|
InputMap.erase_action(&"bugbot_pan_left")
|
||||||
|
InputMap.erase_action(&"bugbot_pan_right")
|
||||||
|
InputMap.erase_action(&"bugbot_movement_speed_up")
|
||||||
|
InputMap.erase_action(&"bugbot_movement_speed_down")
|
||||||
|
InputMap.erase_action(&"bugbot_place_marker")
|
||||||
|
InputMap.erase_action(&"bugbot_exit_placement")
|
||||||
|
#endregion
|
||||||
|
|
||||||
Input.mouse_mode = stored_mouse_mode
|
Input.mouse_mode = stored_mouse_mode
|
||||||
get_tree().paused = stored_pause_status
|
get_tree().paused = stored_pause_status
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
global_transform = stored_camera.global_transform
|
||||||
|
camera.current
|
||||||
|
camera.fov = stored_camera.fov
|
||||||
|
camera.near = stored_camera.near
|
||||||
|
camera.far = stored_camera.far
|
||||||
|
#endregion
|
||||||
|
|
||||||
func _process(_delta:float) -> void:
|
func _process(_delta:float) -> void:
|
||||||
_calculate_movement_speed()
|
_calculate_movement_speed()
|
||||||
|
|||||||
@ -111,6 +111,7 @@ shape = SubResource("SphereShape3D_6gwao")
|
|||||||
debug_color = Color(0.5, 0.7, 1, 1)
|
debug_color = Color(0.5, 0.7, 1, 1)
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="CollisionShape3D"]
|
[node name="Camera3D" type="Camera3D" parent="CollisionShape3D"]
|
||||||
|
current = true
|
||||||
|
|
||||||
[node name="MovementSpeedChangeTimer" type="Timer" parent="."]
|
[node name="MovementSpeedChangeTimer" type="Timer" parent="."]
|
||||||
wait_time = 0.05
|
wait_time = 0.05
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user