fix aiming on elevation
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
class_name FollowingCamera
|
||||
extends Camera3D
|
||||
|
||||
@export var height_offset: float = 0.4
|
||||
@export var distance: float = 6
|
||||
@export var angle_degrees: Vector3
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var follow_position := (
|
||||
Referencer.player.global_position + Vector3.UP * height_offset
|
||||
)
|
||||
|
||||
global_rotation_degrees = angle_degrees
|
||||
global_position = follow_position + transform.basis.z * distance
|
||||
@@ -1,7 +1,12 @@
|
||||
class_name MainCamera
|
||||
extends Camera3D
|
||||
|
||||
@export var current_camera: Camera3D
|
||||
@export var height_offset: float = 0.5
|
||||
@export var distance: float = 50
|
||||
@export var angle_degrees: Vector3 = Vector3(-35, -45, 0)
|
||||
@export var aim_offset_factor: float = 0.2
|
||||
|
||||
var _floor_height: float = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -9,12 +14,18 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
global_position = current_camera.global_position
|
||||
global_rotation = current_camera.global_rotation
|
||||
fov = current_camera.fov
|
||||
near = current_camera.near
|
||||
far = current_camera.far
|
||||
var player_position := Referencer.player.global_position
|
||||
if Referencer.player.is_on_floor():
|
||||
_floor_height = player_position.y
|
||||
player_position.y = _floor_height
|
||||
|
||||
var mouse_pos := get_viewport().get_mouse_position()
|
||||
var aim_position := Player.mouse_project(mouse_pos, player_position, self)
|
||||
|
||||
func is_camera_current(camera: Camera3D) -> bool:
|
||||
return current_camera == camera
|
||||
var aim_relative := aim_position - player_position
|
||||
var follow_position := player_position + aim_relative * aim_offset_factor
|
||||
|
||||
global_rotation_degrees = angle_degrees
|
||||
global_position = (
|
||||
follow_position + Vector3.UP * height_offset + transform.basis.z * distance
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user