Simple Sphere Mesh Rolling Calculations Are Off

I am trying to get a sphere mesh to roll visually on the ground, and feel that I am missing something conceptually due to incorrect results. The same calculations work in non DOTS, which makes me think it is a transform calculation I am using incorrectly or a world/local discrepancy.

Here is the code:

Dependency = Entities.WithName("AddBallRotation")
                .ForEach((Entity e, int entityInQueryIndex
                    , ref ROTATE_BASED_ON_POSITION_CHANGE ballRotate
                    , ref Rotation rotation
                    , in LocalToWorld l2w
                ) =>
                {
                    var movement = l2w.Position - ballRotate.LastPosition;
                    float distance = math.length(movement);
                    if (distance > 0.001f)
                    {
                        float angle = distance * (180f / math.PI) / ballRotate.Radius;
                        //this should be the normal of the ground instead of the float3.Y but just testing on flat ground
                        float3 rotationAxis = math.normalize(math.cross(new float3(0,1,0), movement));

                        var eulerAngle= quaternion.EulerXYZ(rotationAxis * angle);
                      
                        rotation.Value = math.mul(eulerAngle, rotation.Value);
                       
                    }
                    ballRotate.LastPosition = l2w.Position;

                }).Schedule(Dependency);

It seems to spin in a somewhat correct direction, but definitely not matching up correctly, something is out of sorts.

Old Quaternion and new mathematics quaternion are different , the default rotation order is different.

2 Likes

New math library is radian based, call math.radians(angle) before working with the quaternion

Also default quaternion order isn’t XYZ, I can’t recall which one it was but you can check the default parameter from quaternion.Euler, if you’re trying to match Mathf.Quaternion.Euler you need to use the default one

1 Like

Ah, that would explain it. Thank you.

Okay cool, I’ll try doing that and switching up the default orientation. Thanks for the input.