Camera jutter depends on if player is active
This commit is contained in:
parent
16b4c36f26
commit
d328bfcc15
|
|
@ -14,6 +14,7 @@ extends RigidBody3D
|
|||
@export var angular_jitter_speed:Vector3 = Vector3(2, 1, 1)
|
||||
@export var location_jitter:Vector3 = Vector3(0.1, 0.1, 0.1)
|
||||
@export var location_jitter_speed:Vector3 = Vector3(3, 0.3, 1)
|
||||
var jitter_strength: float = 0
|
||||
|
||||
var loc_noise_spot: Vector3 = Vector3.ZERO
|
||||
var rot_noise_spot: Vector3 = Vector3.ZERO
|
||||
|
|
@ -23,27 +24,34 @@ var current_mouse_rotation: Vector2 = Vector2.ZERO
|
|||
var mouse_sensitivity: Vector2 = Vector2(3, 3)
|
||||
var noise: Noise = FastNoiseLite.new()
|
||||
var crouched:bool = false
|
||||
var on_crouch_cooldown:bool = false
|
||||
|
||||
@onready var yaw:Node3D = $Yaw
|
||||
@onready var pitch:Node3D = $Yaw/Pitch
|
||||
@onready var mount:Node3D = $Yaw/Pitch/Mount
|
||||
@onready var camera:Camera3D = $Yaw/Pitch/Mount/Camera3D
|
||||
|
||||
|
||||
func set_active(activate):
|
||||
active = activate
|
||||
if !is_inside_tree(): return
|
||||
if activate:
|
||||
camera.make_current()
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
var jitter_tween: Tween = create_tween()
|
||||
jitter_tween.tween_property(self, "jitter_strength", 1, 1)
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
var jitter_tween: Tween = create_tween()
|
||||
jitter_tween.tween_property(self, "jitter_strength", 0, 0.5)
|
||||
sleeping = active
|
||||
|
||||
func _ready():
|
||||
|
||||
if active:
|
||||
set_active(active)
|
||||
jitter_strength = 1
|
||||
|
||||
_handle_jitter(0)
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
|
|
@ -52,7 +60,7 @@ func _process(delta):
|
|||
func _physics_process(delta:float):
|
||||
_handle_movement(delta)
|
||||
_handle_rotation(delta)
|
||||
_handle_jitter(delta)
|
||||
if jitter_strength > 0: _handle_jitter(delta)
|
||||
|
||||
func _handle_movement(delta:float):
|
||||
var input:Vector2 = Vector2(Input.get_action_strength("player_right") - Input.get_action_strength("player_left"),
|
||||
|
|
@ -100,13 +108,13 @@ func _handle_jitter(delta):
|
|||
noise.get_noise_1d(loc_noise_spot.x),
|
||||
noise.get_noise_1d(loc_noise_spot.y),
|
||||
noise.get_noise_1d(loc_noise_spot.z)
|
||||
) * location_jitter
|
||||
) * location_jitter * jitter_strength
|
||||
|
||||
mount.rotation = Vector3(
|
||||
noise.get_noise_1d(rot_noise_spot.x),
|
||||
noise.get_noise_1d(rot_noise_spot.y),
|
||||
noise.get_noise_1d(rot_noise_spot.z)
|
||||
) * angular_jitter
|
||||
) * angular_jitter * jitter_strength
|
||||
|
||||
|
||||
func _handle_mouse_input(event:InputEventMouseMotion):
|
||||
|
|
@ -118,15 +126,22 @@ func _unhandled_input(event:InputEvent):
|
|||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
_handle_mouse_input(event)
|
||||
|
||||
func _on_bed_enter(body):
|
||||
if not crouched:
|
||||
func _on_bed_enter(_body):
|
||||
if not (crouched or on_crouch_cooldown):
|
||||
$PlayerAnimationPlayer.queue("crouch")
|
||||
max_speed *= .5
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "max_speed", max_speed/2, 0.3)
|
||||
crouched = true
|
||||
|
||||
func _on_bed_exited(body):
|
||||
func _on_bed_exit(_body):
|
||||
if crouched:
|
||||
crouched = false
|
||||
$PlayerAnimationPlayer.queue("stand_up")
|
||||
await $PlayerAnimationPlayer.animation_finished
|
||||
max_speed *= 2
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "max_speed", max_speed*2, 1)
|
||||
|
||||
on_crouch_cooldown = true
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
on_crouch_cooldown = false
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue