ai and game menu
This commit was merged in pull request #23.
This commit is contained in:
@@ -9,32 +9,48 @@ extends Node3D
|
||||
|
||||
@export_group("Ref")
|
||||
@export var rotation_target: Node3D
|
||||
@export var iso_camera: Node3D
|
||||
|
||||
@onready var camera: Camera3D = $%Camera3D
|
||||
|
||||
var total_yaw: float = 0.0
|
||||
var total_pitch: float = 0.0
|
||||
var orbit_distance: float = 0.0
|
||||
var current_pan: Vector2 = Vector2.ZERO
|
||||
var is_active: bool = false
|
||||
var previous_camera: Camera3D
|
||||
|
||||
var initial_local_pos: Vector3
|
||||
var initial_local_basis: Basis
|
||||
|
||||
func _ready() -> void:
|
||||
total_yaw = global_rotation.y
|
||||
total_pitch = global_rotation.x
|
||||
GameState.on_enable_photo_mode_request.connect(enable_photo_mode)
|
||||
GameState.on_disable_photo_mode_request.connect(disable_photo_mode)
|
||||
|
||||
if rotation_target:
|
||||
orbit_distance = global_position.distance_to(rotation_target.global_position)
|
||||
initial_local_pos = position
|
||||
initial_local_basis = basis
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
func enable_photo_mode() -> void:
|
||||
is_active = true
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
previous_camera = get_viewport().get_camera_3d()
|
||||
|
||||
total_yaw = 0.0
|
||||
current_pan = Vector2.ZERO
|
||||
|
||||
if camera:
|
||||
camera.make_current()
|
||||
|
||||
func disable_photo_mode() -> void:
|
||||
is_active = false
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
if previous_camera:
|
||||
previous_camera.make_current()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("toggle_photo_mode"):
|
||||
is_active = !is_active
|
||||
|
||||
#get_tree().paused = is_active
|
||||
|
||||
if !is_active:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
if not is_active:
|
||||
enable_photo_mode()
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
disable_photo_mode()
|
||||
|
||||
if event is InputEventMouseMotion and is_active:
|
||||
total_yaw -= event.relative.x * rotation_speed
|
||||
@@ -43,14 +59,12 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
take_photo_async()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not rotation_target:
|
||||
if not is_active:
|
||||
return
|
||||
|
||||
|
||||
var pan_input = Input.get_vector("photo_pan_left", "photo_pan_right", "photo_pan_up", "photo_pan_down")
|
||||
var rot_basis = Basis.from_euler(Vector3(total_pitch, total_yaw, 0))
|
||||
|
||||
if pan_input != Vector2.ZERO and is_active:
|
||||
if pan_input != Vector2.ZERO:
|
||||
current_pan.x += pan_input.x * pan_speed * delta
|
||||
current_pan.y += -pan_input.y * pan_speed * delta
|
||||
|
||||
@@ -58,15 +72,13 @@ func _process(delta: float) -> void:
|
||||
current_pan.x = clampf(current_pan.x, movement_bounds.position.x, movement_bounds.position.x + movement_bounds.size.x)
|
||||
current_pan.y = clampf(current_pan.y, movement_bounds.position.y, movement_bounds.position.y + movement_bounds.size.y)
|
||||
|
||||
var right_dir = rot_basis.x.normalized()
|
||||
var up_dir = rot_basis.y.normalized()
|
||||
var rotated_basis = Basis(Vector3.UP, total_yaw) * initial_local_basis
|
||||
var rotated_pos = Basis(Vector3.UP, total_yaw) * initial_local_pos
|
||||
|
||||
var final_pan_offset = (right_dir * current_pan.x) + (up_dir * current_pan.y)
|
||||
var local_pos = rotated_pos + (rotated_basis.x * current_pan.x) + (rotated_basis.y * current_pan.y)
|
||||
|
||||
var orbit_pos = rotation_target.global_position + (rot_basis * Vector3(0, 0, orbit_distance))
|
||||
|
||||
global_position = orbit_pos + final_pan_offset
|
||||
global_basis = rot_basis
|
||||
position = local_pos
|
||||
basis = rotated_basis.orthonormalized()
|
||||
|
||||
func take_photo_async() -> void:
|
||||
if !is_active:
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
[node name="PhotoModeController" type="Node3D" unique_id=695158870]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_uhpya")
|
||||
movement_bounds = AABB(-20, -20, 0, 40, 30, 0)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="." unique_id=1369039645]
|
||||
[node name="Camera3D" type="Camera3D" parent="." unique_id=1044424562]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 0.99999994, 0, 0, 0, 0.99999994, 0, 0, 0)
|
||||
projection = 1
|
||||
fov = 96.6
|
||||
size = 35.0
|
||||
near = 0.001
|
||||
far = 500.0
|
||||
|
||||
Reference in New Issue
Block a user