Constraints (Freeze Position & Rotations)

Hi everyone,

I’m looking for a way to freeze rotation of a PhysicsBody like we could with Rigidbody’s Constraints property. How can this be done with DOTS physics?

Thank you!

The PhysicsMass.InverseInertia can be set to float3.zero - i.e. infinite inertia. This is the same as the freeze rotation option. Unfortunately there is no UI for this yet in the Unity Physics package, though if you look at the ‘2b6. Motion Properties - Inertia Tensor’ sample uses a demo script ‘Set Inertia Inverse Behavior’ that you might find useful.

If you want a Joint approach rather than manipulating the tensor check out [this post]( Unity Physics Discussion page-7#post-4460308).

We are looking into an adding the equivalent of the Freeze Position and Freeze Rotation options as full class options in the physics material but I don’t have a timeframe for that yet.

3 Likes

right now I freeze position by removing physics velocity, which I would like to avoid. Should I be able to set InverseMass to 0? In my project I get NaNs and crashes and when I try it in an empty project with a plane and a sphere my sphere falls through the floor

code

public GameObject Prefab;

void Start()
{
    var world = World.DefaultGameObjectInjectionWorld;
    var em = world.EntityManager;
    var settings = new GameObjectConversionSettings(
        world,
        GameObjectConversionUtility.ConversionFlags.AssignName,
        world.GetExistingSystem<ConvertToEntitySystem>().BlobAssetStore);
    var prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(Prefab, settings);
    var e = em.Instantiate(prefab);
    em.SetComponentData(e, new Translation {Value = new float3(10, .5f, 10)});
    {
        var d = em.GetComponentData<PhysicsMass>(e);
        d.InverseMass = 0;
        d.InverseInertia = 0;
        em.SetComponentData(e, d);
    }
}

Setting InverseMass to 0 should be fine. When you create a PhysicsBody as kinematic that is exactly what happens. We certainly shouldn’t be crash. I’ll try for a repro locally.

Pretty sure the crashes are the result of the Nan’s further down the line. Submitting repro project now

Just tried this in the latest released UnityPhysicsSamples project. I can reproduce the crash locally. Let me know when you get a repro project.

(Case 1232765) Unity Physics Setting InverseMass to 0 makes sphere lose collision instead of being frozen. Im guessing this is the same issue as whats causing the crashes in my project, I’ll submit that too if it turns out otherwise. If you could share the fix if its minor I’ll test it

This absolutely works and answers my question – thanks!

1 Like

Ah, ok, there might be a slight miss understanding here.
Infinite Mass and Inertia stop any collisions from imparting impulses to the body i.e. a stoppable force meeting an immovable body. However, if you have already assigned a linear or angular velocity to the body it will continuing moving in the assigned direction or rotating about the assigned axes.
If you have an infinite inertia but a finite mass the body will receive collision impulses through its center of mass, i.e. it will bounce but with no rotation changes.
If you have an infinite mass but a finite inertia the body will receive only angular collision impulses and so will pass through other bodies.
A crash shouldn’t happen though.

Ok, I’ll have another look at the crash

FYI, I checked the sample in your case and didn’t get any crash locally!

hi, from the “2b6. Motion Properties” demo it looks like that setting inertia will lock axis in the world perspective, is it possible to lock the physic body according to his own local axis?

What are you seeing? Setting the inertia inverse already works in the motion space of the body.
Note that motion space and body space may be different if you have overridden the default mass distribution and moved the center of mass or motion orientation. The last Cube in 2b6 looks like it is locked in world space because the mass properties are re-oriented.
6038543--652406--upload_2020-6-30_11-19-34.png

Thanks, will take a look at the orientation.

Works for me exactly:):slight_smile: