Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics 2D and joints

Discussion in '2D' started by Juliken, Mar 21, 2019.

  1. Juliken

    Juliken

    Joined:
    Jan 30, 2017
    Posts:
    17
    Hello, I'm currently prototyping a 2D game but I have problems with my physic logic.

    Let me explain the game. During a conversation, words will appear on the screen and the player's goal is to connect words between them to create a logical sequence.



    Every word has "markers" (red dots) and I used them to connect the words. When the player connects 2 words, it connects the markers with the same type on each word. Every marker is connected to his word with spring joint so they cant move from the word and they slide around the word.

    When I connect 2 words, it create an other spring joint between 2 markers so the markers get closer to each other and the words are pulled by the markers.



    So what I want to do is a system that allow markers to slide properly around their word and when they are connected to an other marker, they both slide to the closest position of the other marker and it pull the word with it (2nd image). I used spring joint for everything but the result isn't exactly what I expected. Do you have any idea for doing this ?

    Thanks in advance and sorry for my english.
     
  2. beanie4now

    beanie4now

    Joined:
    Apr 22, 2018
    Posts:
    311
    I would do it using line renderers. Probably the line renderers would have grabbabe anchors at the ends that would snap to a word OnTriggerEnter. It would then calculate Mathf.distance i think its mathf.... but theres a distance calculator you can use. If the distance between anchors/words is greater than int you can use MoveTowards() or Lerp()