Freeze rotation

I'm looking to simply freeze the X and Z rotation of my rigidbody, but the authoring settings don't seem to work - when the character's capsule collider is falling and touches a corner, it rotates.

I've tried using the "Freeze Rotation" settings directly (no change). I've also tried setting manual inertia tensor to 0, 1, 0 but this breaks collision completely for the entity.

The goal is to have a 3d character locked upright on a 2d plane. Any advice would be much appreciated.

9506212--1339366--upload_2023-12-1_21-47-16.png 9506212--1339369--upload_2023-12-1_21-47-52.png

Unity 2022.3.13f1
Physics 1.2.0-exp.3 (Unity, not Havok)

I'm still new to ECS, but I might be able to help with some ideas

Just gave it a go myself and reckon you're onto it by suspecting a baking issue. Rigidbody constraints don't seem to be baked or handled at all (yet, at least). So you might have to write your own constraint component, your own baking for the constraints, and your own system for implementing the constraints to the entities.

I'm unsure if there's more modern ways of doing it, but it does seem to get the job done.

I've found a few sources which might be useful in how to do it. But some of it is outdated (eg old authoring methodology):
https://discussions.unity.com/t/865810
https://discussions.unity.com/t/736062 page-6#post-4448050
https://docs.unity3d.com/Packages/com.unity.physics@1.2/api/Unity.Physics.PhysicsJoint.SetConstraints.html

Thanks for the links. I remember using the specialised authoring and the sample constraints a few years back, however afaik the default physics monobehaviours were supposed to be supported now? Changing the inertia tensor at least does "something", even though it's not what I expected.

If the authoring isn't yet fully supported then so be it, I'd just like and hope that basic physics features would Just Work in a post v1 package.

1 Like

Yeah, I was hoping for the same. Could be that we're just missing it somehow. Does seem very odd that it wouldn't work out the box.

Out of curiosity, how do the tensor changes break collisions? They stop altogether, or something more specific?

Yup, collisions just outright don't occur, so my character falls through the floor.

Weird... Guessing you're not getting compiler warnings either.

Can I see what code you're using to change the inertia tensor? You're modifying entities rather than doing it through monobehaviour?

https://docs.unity3d.com/Packages/com.unity.physics@1.2/api/Unity.Physics.PhysicsMass.html

Nah, just through the monobehaviour authoring, as shown in the screenshots in my first post. I have no custom physics code running at all yet.

Spent the day trying to figure out a good solution to this, but I'm not quite there with my understanding yet.

But on the plus side, I've found this:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/PhysicsSamples/Assets/4.%20Motion%20Properties

Haven't checked it myself yet, and I'm unsure if it still works for 1.2 (though I suspect it will, since it's 1.0). Should be as simple as cutting out the bits you need. Let me know if you run into any issues or have some success with it though.

Worst case scenario, I imagine it's fairly high up on their priorities for future versions, since it's a pretty basic requirement