57 lines
1.4 KiB
GDScript
57 lines
1.4 KiB
GDScript
class_name MainCamera
|
|
extends 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_mouse: float = 0.2
|
|
@export var _aim_offset_factor_controller: float = 0.5
|
|
@export var _aim_damping: float = 1
|
|
|
|
var _floor_height: float = 0
|
|
var _aim_offset: Vector3
|
|
|
|
|
|
func _ready() -> void:
|
|
Referencer.main_camera = self
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
_follow(delta)
|
|
|
|
|
|
func _follow(delta: float) -> void:
|
|
var player_position := Referencer.player.global_position
|
|
if Referencer.player.is_on_floor():
|
|
_floor_height = player_position.y
|
|
player_position.y = _floor_height + Projectile.HEIGHT
|
|
|
|
if Inputer.mode == Inputer.Mode.KB_MOUSE:
|
|
_aim_offset = Referencer.player.aiming.aim_offset
|
|
else:
|
|
var new_aim_offset := (
|
|
Vector3.ZERO
|
|
if Referencer.player.aiming.aim_input.length() == 0
|
|
else Referencer.player.aiming.aim_offset
|
|
)
|
|
_aim_offset = _aim_offset.lerp(new_aim_offset, _aim_damping * delta)
|
|
|
|
var follow_position := (
|
|
player_position
|
|
+ (
|
|
_aim_offset
|
|
* (
|
|
_aim_offset_factor_mouse
|
|
if Inputer.mode == Inputer.Mode.KB_MOUSE
|
|
else _aim_offset_factor_controller
|
|
)
|
|
)
|
|
)
|
|
|
|
global_rotation_degrees = _angle_degrees
|
|
global_position = (
|
|
follow_position + Vector3.UP * _height_offset + transform.basis.z * _distance
|
|
)
|
|
|
|
Debugger.circle("follow_position", follow_position)
|