Right now I'm using this code, but the transition glitches from one border to another

void Start()
    if(isLeft == false)
        destination = GameObject.FindGameObjectWithTag("LeftBorder").GetComponent<Transform>();
        destination = GameObject.FindGameObjectWithTag("RightBorder").GetComponent<Transform>();

private void OnTriggerExit2D(Collider2D collision)
    if (Vector2.Distance(transform.position, collision.transform.position) > distance)
        collision.transform.position = new Vector2(destination.position.x, destination.position.y);
  • 2
    \$\begingroup\$ Assume your reader has not played doodle jump. Explain the behaviour that you want this code to achieve, and how precisely the current behaviour differs from that. \$\endgroup\$
    – DMGregory
    May 31, 2021 at 20:55
  • \$\begingroup\$ A player character is moving to the right, as soon as he dissapeares from the screen, player character reapers from the left side of the screen \$\endgroup\$
    – koogel
    May 31, 2021 at 20:59
  • \$\begingroup\$ Start is only executed once. This code should not work when you decide to go the other way. \$\endgroup\$
    – Zibelas
    Jun 1, 2021 at 12:12
  • 1
    \$\begingroup\$ @koogel Please edit your question to include your clarifying explanation directly in your question post. Comments are somewhat temporary - if the information is important, it should be edited into the corresponding question/answer. \$\endgroup\$
    – Pikalek
    Jun 1, 2021 at 15:23


You must log in to answer this question.

Browse other questions tagged .