Search Unity

Random position valid for a hinge

Discussion in 'Physics' started by arklay_corp, May 8, 2019.

  1. arklay_corp

    arklay_corp

    Joined:
    Apr 23, 2014
    Posts:
    242
    Hi all,

    I'm trying to find a way to set a valid rotation and position for a gameobject that has a joint attached.

    Being specific:

    I have a ragdoll that works properly when activated setting all rigidbodies as not kinematic.

    What I want to do is, keeping the rigidbodies disabled, create a random pose for the character that doesnt violate the character joints (and therefore it is a "natural" position)

    I want to avoid using animations and pausing them, or activating physics and using forces and then pausing the physics.

    Any ideas?
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    If you want a random pose for a set of constrained bodies, just randomize the local rotation (and position, if applicable) of each part within their allowed ranges of motion (need to define rotation limits for each axis on each part).

    The are some possible problems with this method, such as getting poses with self-intersection or, more generally, rotation constraints that are more complex than just a range of angles for each axis. If you have these problems, depending on how often you need to do this and how many parts are being randomized a Monte Carlo approach could work fine. Randomize the parameters, then check for validity afterward. If it's invalid, re-roll some or all of the parameters and check again.

    If your objects aren't using physics (Rigidbody disabled), you don't really need joints, either-- the parenting will take care of relative positioning of children when a higher-level part is moved. I don't understand how a ragdoll works into this, though, because you can't really have a proper ragdoll without some kind of physics in place, which would mean using Rigidbody's and joints.