Rotating a Non-Uniform Scaled Collider

Hey everyone,

So I stumbled upon the same issue as explained here, however I don't have a LocalToWorld to use:

I start off with a rotated non-uniformly scaled GameObject prefab, which only consists of a collider. I convert it to an Entity and then when trying to apply rotations to it, it doesn't rotate correctly with the GameObject. In this specific case I simply copy + paste the rotation from the visual (as seen in the picture) to the entity (which is the collider).

This works fine if the prefab itself has all rotational values to 0.

Some fixes given in the thread above are to use:
- quaternion.LookRotationSafe(fwd, up)
- Unity.Physics.Math.DecomposeRigidBodyOrientation(localToWorld.Value)

However the rotation I'm copying is not from an Entity, so I cant use LTW from the visual object, I've tried creating a new LTW component on the go with the visuals' position / rotation / scale but it doesn't seem to work. Altering the LTW component itself didn't give me the results I am looking for either.

Now I could fix it by rotating all objects used in the prefab to a zero rotation in blender, but I'm sure there's a better solution for this where I can freely use rotations / scaling in prefabs before converting & applying rotations on it later.

For info: Im using the latest entity/havok packages

Thanks in advance!


Unless I'm understanding your problem incorrectly, I changed the default sync system to solve this issue in this thread Simply create that script, and then add a new Authoring Component script onto the object you want rotated so the system knows to sync your object (in my script I call it "MyFixedSync") like so...

using Unity.Transforms;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Entities;

public struct MyFixedSync : IComponentData

Also fair warning this script doesn't seem to be burst compatible unless you disable safety checks "Jobs > Burst > Safety Checks" or just delete the line [BurstCompile]

I do run my own sync system as I don't need to set the position/rotation/scale every frame, and coincidentally I found your thread before the one I posted. However I'm trying to copy the rotational values from a GameObject and not another Entity, which makes the difference :(

Thanks anyway for the input!

Just to clarify: turns out that moving / rotating after prefab conversion is working as expected regardless of rotation / scale in the prefab.

However after using a custom scale tool the GO which is used to generate the collider is scaled accordingly and then when I regenerate the collider things go wrong when setting the rotation after that. At uniform size the rotations are fine but any non-uniform scale is wrong. This seems to only apply if the original GO had some rotational non-zero value.

The rotations of the collider are being set correctly, so it seems regenerating a non-uniform collider is part of the cause?


1 Like

I think you’re running into the problem again that, after conversion, scale is baked into the physics shape. This is an old thread but maybe something like the CompositeScale component may help? . I would also take a look at the CopyTransformFromGameObjectSystem.cs to see how Unity applies transformation to an entity from the GO data.

Have you tried doing what that system does and setting a new localToWorld for your entity using the GO’s properties?

                localToWorld = new LocalToWorld
                    Value = float4x4.TRS(
                        new float3(1.0f, 1.0f, 1.0f))
1 Like

I’ve tried CompositeScale & setting the LTW matrix before, but no result with either of those unfortunately. It seems that I have to regenerate the colliders after scaling regardless as scalable objects have colliders varying from box to mesh. (I could technically make a scaling option for every single physicsshape as mentioned in the examples, but for meshes it would still require a regeneration)

It feels like if the converted entity is a child of an object which has rotational values those values are somehow embedded into the collider as well. I’ve included an example gif (with blue background) of this where the left boxcollider entity is a child of an object which is rotated 5, -45, 0. And the right one is just 0,0,0. As for the top parent this is also 0,0,0.

When scaling in this gif, the colliders are regenerated constantly, as soon as its not uniform the left collider just rotates wrongly.

I’ve included another gif where I rotate the collider in the prefab itself, this is with the root parent scaling set to 1.1, 0, 0. (Other values are the same as described above)


1 Like

I've had a similar problem for a while I have yet to solve. There's a lot of things you cant do with the current state of colliders in DOTS and it seems like you'll just have to regenerate it . Let me know if you get it working, as I'd love to solve this as well.

In the end I just adjusted all models which were used in prefabs so that their prefab orientation was 0,0,0.

I'm sure there's a way to figure out the reverse calculation to not do this, but I don't have all the time to figure it out, I did manage to see that the children who where rotated by 90 degree steps would rotate fine with the parent for whatever reason :)