17 lines
585 B
GDScript
17 lines
585 B
GDScript
extends Node2D
|
|
|
|
@export var max_offset := Vector2.ONE
|
|
|
|
var _last_global_position: Vector2
|
|
var _local_offset: Vector2
|
|
|
|
func _ready() -> void:
|
|
_last_global_position = global_position
|
|
_local_offset = position
|
|
|
|
func _process(_delta: float) -> void:
|
|
var parent_position: Vector2 = get_parent().global_position
|
|
var target_position := parent_position + _local_offset
|
|
var new_position: Vector2 = lerp(_last_global_position, target_position, 0.4)
|
|
global_position = target_position + (new_position - target_position).clamp(-max_offset, max_offset)
|
|
_last_global_position = global_position
|