Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Custom Constraint

Discussion in 'Physics for ECS' started by MicCode, Jan 14, 2021.

  1. MicCode


    Nov 19, 2018
    The Physx SDK allow user to implement custom constraint

    User can implement a custom joint type and let the physics engine to solve the constraint
    Which allow user to do something like this

    Is there anyway to do it with DOTS Physics(Unity or Havok)
    I've never used Havok c++ sdk before, does it allow custom constraint like this?
    Is it possible for DOTS Physics to have something like this as well?
  2. Sab_Rango


    Aug 30, 2019
    Hi! I think you have to do it manually!
    This is created by ratio algorithm.
    For instance, there are 2 connected circle chains, 1st has radius R, 2nd one 2R. IF 1st revolves 2*PI radian , second must be revolved 1/2R*PI radian.

    There is no this revolution joint system in DOTS physics. But You can customize any new joint system to the engine!
  3. MaxAbernethy


    Mar 16, 2019
    Hello, there is no existing gear constraint in DOTS physics. You can create one but it will take some work:

    1) Use a hinge joint to fix the gears on their axles
    2) Create a custom joint to model the interaction of the gears' teeth. There is actually no way to constrain two bodies' rotations with a ratio, which as Sab_Rango said is needed if the gears do not have the same radius, but you can do it with a linear constraint at the point where the teeth meet. For example if you had a gear at (0, 0, 0) with radius 1 and a gear at (3, 0, 0) with radius 2 both rotating about (0, 0, 1), then you would create a linear constraint in the Y axis at (1, 0, 0) in world space. You would need to update the joint's transforms every step, because as the gears turn the location where they meet in their local spaces changes; it is always (1, 0, 0) in world space, but it changes in local space. Same for the direction.
    3) The gears will drift because of solver error, so you will need to correct that or it will look wrong, especially if the gears do not have any play, and it will also accumulate over time. A simple approach would be to start from one gear, then traverse the tree of connected gears snapping each one the correct rotation based on its parent.

    I tried this a while ago but the code is long lost, sorry. I only did the first two steps, but I'm pretty sure that with some correction as described in step (3) it would work.