GrappleTest/Objects/MovingPlatform/MovingPlatform.gd
2024-03-17 21:56:16 -05:00

29 lines
914 B
GDScript

extends AnimatableBody2D
@export var endPoint : Vector2
var velocity = Vector2.ZERO
var moving = false
func _on_area_2d_body_shape_entered(body_rid, body, bod_shape_index, local_shape_index):
if not moving:
moving = true
var tween = create_tween()
tween.set_parallel(true)
tween.set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
var dur = position.distance_to(position + endPoint) / 750
tween.tween_property(self, "position", position + endPoint, dur)
tween.tween_property(self, "velocity", endPoint / dur / 3, dur / 2)
tween.tween_property(self, "velocity", Vector2.ZERO, 1.25).set_delay((dur / 2))
tween.chain()
tween.tween_property(self, "position", position, dur).set_delay(2)
tween.tween_property(self, "velocity", -endPoint / 3, 1).set_delay(2)
tween.tween_property(self, "velocity", Vector2.ZERO, 1.25).set_delay(3)
await tween.finished
moving = false