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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mass rotation of children rigidbodies around point? Is it possible?

Discussion in 'Physics' started by Rich0, Apr 7, 2016.

  1. Rich0

    Rich0

    Joined:
    Aug 9, 2013
    Posts:
    50
    I am trying to create a master "container" object which allows me to effectively rotate a scene - kind of like rotating a chess-board with all it's child pieces in tact, except the pieces are also shooting rigidbodies at each other.

    Is this possible?
     
    Last edited: Apr 7, 2016
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    I don't see why it wouldn't be possible. But if you're rotation everything in a scene around one axis, why not just move the camera?
     
  3. Rich0

    Rich0

    Joined:
    Aug 9, 2013
    Posts:
    50
    Thanks for your reply. I can't move the camera because I'm using VR. Looking forward to help with this!
     
  4. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Have you tried it? Are there any reasons why you think it won't work? It sounds ok to me, but I don't want to say I'm sure. I could see some potential problems with physics, if applicable.

    As long as all movement of objects is local, I think it will work for limited cases, but Rigidbody's will probably have some trouble as they try to retain their velocities while being rotated.
     
  5. Rich0

    Rich0

    Joined:
    Aug 9, 2013
    Posts:
    50
    Yes, I have tried it. Any children of the partner with a rigid body attached don't rotate properly.
     
  6. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    What do you expect to happen when you make the rotation, and what actually happens?
     
  7. Rich0

    Rich0

    Joined:
    Aug 9, 2013
    Posts:
    50
    I expect the children (rigidbodies) will rotate in the same manner as the non rigidbody children. I also expect the rigidbodies direction of movement will also be altered to match the rotation of the parent object.

    What actually happens is the non-rigid bodies rotate normally, however the rigidbody children seem to rotate at a slower rate and continue their original velocity (however it seems this velocity is slightly changed).
     
  8. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    Okay so bear with me on this one since I'm not on a computer right now, but there's not reason this shouldn't work. Use OnPre and OnPostRender to rotate the parent object and then undo the rotation, respectively. So essentially while your physics simulation will occur in non-rotated space, to the viewer everything should be rotating as expected. And since you undo the rotation before the physics step is run again, Unity is none the wiser.
     
  9. KristoE

    KristoE

    Joined:
    Oct 13, 2012
    Posts:
    90
    Ok, maybe a dumb question, but why can't you move the camera when using VR?
    However, I agree with others that, in theory, it should work regardless.
    What method are you using to rotate the parent object?
    I know that the physics engine might do some funky stuff when you try to rotate it in the editor.

    Also, if nothing else works, there might be a slightly more complicated solution.
    Code the rotation yourself without using the parent object. Do the rotation of each object individually and change the velocity yourself as well.

    Just some useful functions to look into if you decide to try to code the rotation yourself.

    transform.TransformDirection();
    transform.InverseTransformDirection();
    transform.TransformPoint();
    transform.InverseTransformPoint();
    transform.TransformVector();
    transform.InverseTransformVector();

    Although there probably is a simpler way.