Here's the code I'm trying to get to work.
public partial struct MovementSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
foreach (var (localTransform, velocity, forward) in
SystemAPI.Query<RefRW<LocalTransform>,RefRO<VelocityComponent>, RefRW<ForwardComponent>>())
{
localTransform.ValueRW.Position += velocity.ValueRO.Velocity;
//Problem
Quaternion rotationQuaternion = math.normalize(Quaternion.Euler(0f, 0f, velocity.ValueRO.Rotation * 10000));
Debug.Log("rotationQuaternion: " + rotationQuaternion + "velocity.ValueRO.Rotation: " + velocity.ValueRO.Rotation);
localTransform.ValueRW.Rotate(rotationQuaternion);
//localTransform.ValueRW.RotateZ(velocity.ValueRO.Rotation);
var cosAngle = math.cos(velocity.ValueRO.Rotation);
var sinAngle = math.sin(velocity.ValueRO.Rotation);
var x = forward.ValueRO.Forward.x;
var y = forward.ValueRO.Forward.y;
forward.ValueRW.Forward = math.normalize(new float3(cosAngle * x - sinAngle * y, sinAngle * x + cosAngle * y, 0f));
//This works on local transform, but doesn't work in drawing
//localTransform.ValueRW.Rotation = math.normalize(Quaternion.Euler(forward.ValueRO.Forward));
}
}
}
The only version that actually applies rotation is the lowest one, setting the rotation manually. However, the entity in question has a Sprite2D as a child, and the sprite2D localtransform does not update when I set the localtransform on the parent. Using the localtransform.rotate/rotatez does not update the parents localtransform at all.