Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Rotation of child objects

Discussion in 'Scripting' started by riottaver, Jun 2, 2020.

  1. riottaver

    riottaver

    Joined:
    Apr 30, 2020
    Posts:
    7
    I'm doing this game in which two players controls two pirates, and they have to survive from objects falling from the sky while stading on the top of a plank, that works just like a seesaw.

    normal_equidou.png

    I'm having problems with the rotation of the pirates, they are parented with the plank (seesaw), when the plank rotates they also rotate, however their sprite become stretched as you can see below

    errado_equidou.png

    If you have some spare time and can help me out, I would be very greatful
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Hello again, we talked a few days ago. Are you scaling any of those components?? I think what you want to do is have each object on a "clean" part of the hierarchy, NOT scaled. Maybe like so:

    Code (csharp):
    1. TheBoat (scale (1,1,1))
    2. --- TheBoatGraphic (scaled as needed)
    3. --- TheSailGraphic (scaled as needed)
    4. --- TheSeeSawAttachPoint (scale (1,1,1))
    5. ------ TheSeeSawPivotPoint (scale (1,1,1))
    6. ---------- The SeeSawGraphic (scaled as needed)
    7. ---------- Pirate1 (scaled as needed)
    8. ---------- Pirate2 (scaled as needed)
    The slewing you see happens when you interleave scaling and rotation and then more scaling going down a hierarchy.

    (I snuck in here for some Ninja edits...)
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Currently your Hierarchy is this:
    (A) Plank (SpriteRenderer) <some local scale>
    - (B) Pirate (SpriteRenderer)
    - (C) Pirate (SpriteRenderer)

    And A probably has a local scale set to get the right shape for your plank, right?

    Try a hierarchy like this:
    (A) Plank (empty) <local scale = (1, 1, 1)
    - (B) Pirate (SpriteRenderer) <some local scale>
    - (C) Pirate (SpriteRenderer) <some local scale>
    - (D) Plank sprite (SpriteRenderer) < some local scale>
     
  4. riottaver

    riottaver

    Joined:
    Apr 30, 2020
    Posts:
    7

    Hello again, glad you're back

    So I'm not sure if I follow you, how can I scale the pivot point and the attach point?
     
  5. riottaver

    riottaver

    Joined:
    Apr 30, 2020
    Posts:
    7

    I tried to attach all of them to an empty object, but the pirates just stop rotating
    hier.png
    ssa.png
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    What's the thing that you are rotating now? The plank, or the empty GameObject? You should rotate the empty object that is now the parent of the plank and the pirates.
     
  7. riottaver

    riottaver

    Joined:
    Apr 30, 2020
    Posts:
    7
    The issue is that the plank moves because of the hinge joint component, the movement is not scripted, its just phisics. So i tried to put a hinge joint in the empty object, however the pirates and the plank dont rotate along with it, i'm confused with which components from the plank should go to the empty gameobject and which should stay.

    The plank has a rigidbody 2d, a hinge joint 2d, a box collider and the sprite renderer
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Make a fresh scene and do some pivot testing first... you might find that the pirates need a SlidingHinge2D to connect them to the plank, otherwise they'll likely fall through it, or their weight will be unevenly applied to the plank.

    Computer physics simulations do not do well with multiple items in close contact and interacting, like sliding along each other, because the solvers try to counter it all and can get jittery, so it is often necessary to help the physics with extra hinges, which might need to be broken when you jump (if you jump), etc.

    You can look up tutorials for jumping on moving platforms because that's basically exactly what you're doing here, except you also want the pirate's weight to affect the physics, so it's even more tricky.