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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Low-level physics - Creating a new kind of joint

Discussion in 'Physics' started by dgoyette, Apr 1, 2018.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    There seem to be a handful of folks who really dig deep when it comes to customizing the physics of their game. Aside from disabling Unity's physics engine, and building one entirely from scratch, I'm curious how these devs access some of the lower-level functionality of the physics engine.

    To provide a concrete example of what I mean, I'm interested in building a Joint that Unity currently doesn't have. Call it a "resistant" joint. It's similar to a Fixed joint, completely constraining relative motion of the two rigidbodies. However, the joint should allow motion if enough force is applied, and NOT spring back to its original shape. As a real-work example, think of a metal rod. It takes a lot of force to bend it, but (depending on the kind of metal) it stays in that bent shape afterwards, and does not spring back to its original shape.

    None of the joints in Unity support this kind of behavior, so it might be a lost cause, but I was curious about how I'd approach building such a joint on my own. Are Unity's existing joints just using the underlying PhysX joints? Is it possible to author PhysX extensions to be used by Unity?

    I'm not asking specifically how to make this joint. I'm wondering mainly the feasible general approaches to extending the physics system in Unity.

    Thanks,

    -Dan
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,423
    As far as I know, there's no way to extend PhysX beyond what's exposed in Unity. Any customization comes from tricks that use Unity physics layer in creative ways based on deep knowledge on how the underlying PhysX works. This knowledge not only comes from the available documentation and source code, but also from extensive tests where one can evaluate the physics response under certain conditions. As result, one can figure out solutions to specific situations using the parameters and components exposed in Unity.

    How would I approach the kind of joint proposed by you? I'd begin with a rigid link. Joints in PhysX are not really rigid, but there's always some degree of movement allowed. I'd try monitoring that movement. If the movement with respect to the original position surpasses some threshold, we may assume that the object is suffering a significant amount of force. I'd then move the original joint position (and/or rotation) in the direction of the detected movement. This way the joint would have a new "bent" position. The same force in the opposite direction would move the joint back to the original position.

    That's just a first thought on how I would approach that problem in Unity. The final solution may probably vary depending on the results on the preliminary tests. Maybe there are further situations that must be accounted for.

    It has been announced that the upcoming PhysX update in Unity will expose more of the physics engine allowing further customizations. We'll see then.
     
    Last edited: Apr 2, 2018
    dgoyette likes this.
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Are you looking for joint motor, perhaps with some simple scripting to set the origin each frame?
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    Thanks for the context, Edy. And that's an interesting approach to the joint I'm trying to create. I'll see how well it works.

    -Dan