godot-parkour/content/scripts/dampened_camera.gd

35 lines
751 B
GDScript3
Raw Permalink Normal View History

class_name DampenedCamera3D extends Camera3D
2024-02-23 12:09:40 +00:00
@export var target: Node3D
@export var damping: bool
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
damping = false
set_process_priority(100)
set_as_top_level(true)
Engine.set_physics_jitter_fix(0.0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if target == null:
pass
global_rotation = target.global_rotation
var target_pos := target.global_position
if not damping:
global_position = target_pos
pass
target_pos.y = lerp(global_position.y, target_pos.y, 20 * delta)
global_position = target_pos
2024-02-23 12:09:40 +00:00
func damp() -> void:
damping = true
2024-02-23 12:09:40 +00:00
func donmp() -> void:
damping = false