23 lines
624 B
GDScript
23 lines
624 B
GDScript
extends Area3D
|
|
|
|
var stuck = null
|
|
var alpha = 0.01
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
body_entered.connect(_on_area_entered)
|
|
body_exited.connect(_on_area_exited)
|
|
|
|
func _physics_process(delta):
|
|
if (stuck != null):
|
|
stuck.global_position.x = lerp(stuck.global_position.x, global_position.x, 1 - alpha ** delta)
|
|
stuck.global_position.z = lerp(stuck.global_position.z, global_position.z, 1 - alpha ** delta)
|
|
|
|
func _on_area_entered(body : RigidBody3D) -> void:
|
|
stuck = body
|
|
print ("stuck!")
|
|
|
|
func _on_area_exited(body : RigidBody3D) -> void:
|
|
stuck = null
|
|
print ("unstuck!")
|