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.