extends AnimatableBody2D @onready var tip = $"Tip" var detecting = true var velocity = Vector2.ZERO @onready var startPos = global_position func _on_anim_trigger_body_shape_entered(body_rid, body, body_shape_index, local_shape_index): if detecting: detecting = false var tween = get_tree().create_tween() var space_state = get_world_2d().direct_space_state var query = PhysicsRayQueryParameters2D.create(tip.global_position, tip.global_position + Vector2(0, 500).rotated(global_rotation)) var result = space_state.intersect_ray(query) var finalPos = Vector2(0, 400).rotated(global_rotation) if result: finalPos = result.position - tip.global_position tween.set_trans(Tween.TRANS_CUBIC) tween.set_parallel(true) tween.tween_property(self, "global_position", global_position + finalPos, 0.5).set_ease(Tween.EASE_IN) tween.tween_property(self, "velocity", Vector2(0, 700).rotated(global_rotation), 0.5).set_ease(Tween.EASE_IN) await tween.finished tween = get_tree().create_tween() tween.set_parallel(true) tween.tween_property(self, "global_position", startPos, 2).set_trans(Tween.TRANS_SINE).set_delay(1).set_ease(Tween.EASE_IN) tween.tween_property(self, "velocity", Vector2.ZERO, 0.5).set_trans(Tween.TRANS_SINE).set_delay(0.25).set_ease(Tween.EASE_IN) #await get_tree().create_timer(0.25).timeout #constant_linear_velocity = Vector2.ZERO await tween.finished detecting = true