Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Help keeping sprite attatched to ridgidbody.

Discussion in 'Physics' started by JeremyToler, Sep 19, 2019.

  1. JeremyToler

    JeremyToler

    Joined:
    Jul 11, 2015
    Posts:
    17


    I have a 2D pixel art circle with a triangle that I want to have spin around it, then when it is ready to be launched I want the whole object to launch forward. Right now the rigidbody and attached triangle launch forward but leave the circle sprite behind. How can I fix this? What is the standard practice way to move a component with a rigidbody that is not directly attached to it?

    I separated the circle from the ridgidbody2D because I wanted to keep the circle from moving when the triangle is spinning.

    Currently I have a game object that contains the script that controls movement then childed under that I have the rigidbody and the circle sprite, childed under the rigidbody is the triangle. Here's an image of the hierarchy - https://imgur.com/a/78ullue
     
  2. JeremyToler

    JeremyToler

    Joined:
    Jul 11, 2015
    Posts:
    17
    This was the solution I came to. I don't know if correcting the position every update is the best solution, if you know of a better one please let me know.

    Code (CSharp):
    1.     public void LateUpdate()
    2.     {
    3.         transform.position = body.transform.position;
    4.     }
     
  3. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    892
    You could use a joint to attach the objects to each other.
     
  4. JeremyToler

    JeremyToler

    Joined:
    Jul 11, 2015
    Posts:
    17
    Thanks, would I have to attach a physical object to it? I couldn't figure out a way to attach just a sprite with a joint.