add offset damping on controller input
This commit is contained in:
parent
86e59dce55
commit
7209740950
@ -1,35 +1,45 @@
|
||||
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: float = 0.2
|
||||
@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
|
||||
@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()
|
||||
func _process(delta: float) -> void:
|
||||
_follow(delta)
|
||||
|
||||
|
||||
func _follow() -> void:
|
||||
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
|
||||
|
||||
var follow_position := (
|
||||
player_position + Referencer.player.aim_offset * aim_offset_factor
|
||||
)
|
||||
if Inputer.mode == Inputer.Mode.KB_MOUSE:
|
||||
_aim_offset = Referencer.player.aim_offset
|
||||
else:
|
||||
var new_aim_offset := (
|
||||
Vector3.ZERO
|
||||
if Referencer.player.aim_input.length() == 0
|
||||
else Referencer.player.aim_offset
|
||||
)
|
||||
_aim_offset = _aim_offset.lerp(new_aim_offset, _aim_damping * delta)
|
||||
|
||||
global_rotation_degrees = angle_degrees
|
||||
var follow_position := player_position + _aim_offset * _aim_offset_factor
|
||||
|
||||
global_rotation_degrees = _angle_degrees
|
||||
global_position = (
|
||||
follow_position + Vector3.UP * height_offset + transform.basis.z * distance
|
||||
follow_position + Vector3.UP * _height_offset + transform.basis.z * _distance
|
||||
)
|
||||
|
||||
Debugger.circle("follow_position", follow_position)
|
||||
|
||||
@ -9,14 +9,15 @@ const FALL_SPEED: float = 20
|
||||
const FALL_ACCELERATION: float = 25
|
||||
|
||||
@export var _respawn_height: float = -5
|
||||
@export var _aim_mult_x: float = 20
|
||||
@export var _aim_mult_y: float = 27
|
||||
@export var _controller_aim_offset: float = 20
|
||||
|
||||
var aim_offset: Vector3
|
||||
var aim_input: Vector2
|
||||
|
||||
var _respawn_point: Vector3
|
||||
var _floor_height: float = 0
|
||||
var _floor_height: float
|
||||
var _move_input: Vector2
|
||||
var _move_direction: Vector3
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -46,16 +47,22 @@ func _controller_aiming() -> void:
|
||||
if Inputer.mode != Inputer.Mode.CONTROLLER:
|
||||
return
|
||||
|
||||
var aim_input := Input.get_vector("aim_left", "aim_right", "aim_up", "aim_down")
|
||||
aim_input = Input.get_vector("aim_left", "aim_right", "aim_up", "aim_down")
|
||||
|
||||
if aim_input.length() == 0:
|
||||
if aim_input.length() == 0 and _move_input.length() == 0:
|
||||
return
|
||||
|
||||
var aim_input_norm := aim_input.normalized()
|
||||
var aim_direction := (
|
||||
Vector3(aim_input.x, 0, aim_input.y)
|
||||
if aim_input.length() > 0
|
||||
else Vector3(_move_input.x, 0, _move_input.y)
|
||||
)
|
||||
|
||||
aim_offset = (
|
||||
Vector3(aim_input_norm.x * _aim_mult_x, 0, aim_input_norm.y * _aim_mult_y)
|
||||
. rotated(Vector3.UP, Referencer.main_camera.rotation.y)
|
||||
aim_direction.normalized().rotated(
|
||||
Vector3.UP, Referencer.main_camera.rotation.y
|
||||
)
|
||||
* _controller_aim_offset
|
||||
)
|
||||
|
||||
look_at(global_position + aim_offset, Vector3.UP, true)
|
||||
@ -104,10 +111,10 @@ func _lateral_movement(delta: float) -> void:
|
||||
_move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
||||
if _move_input.length() > 0:
|
||||
var direction := Vector3(_move_input.x, 0, _move_input.y).normalized()
|
||||
var new_velocity := (direction * MOVE_SPEED).rotated(
|
||||
_move_direction = Vector3(_move_input.x, 0, _move_input.y).normalized().rotated(
|
||||
Vector3.UP, Referencer.main_camera.rotation.y
|
||||
)
|
||||
var new_velocity := _move_direction * MOVE_SPEED
|
||||
new_velocity.y = velocity.y
|
||||
velocity = velocity.move_toward(new_velocity, MOVE_ACCELERATION * delta)
|
||||
else:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user