I started to work with ECS and I have a Rotation component (quaternion) and a Translation component (float3). I am writing a System that will handle user input and rotate and/or move forward the player.
The problem is I don't know how to do it. The existing API is lacking in my opinion.
// Before it was easy
if (Input.GetKey(KeyCode.W))
var newPostion = new Vector3(player.Position.x, player.Position.y, 0.3f)
+ _playerTransform.up * Time.deltaTime * PlayerSpeed;
if (Input.GetKey(KeyCode.A))
_playerTransform.Rotate(new Vector3(0, 0, PlayerRotationFactor));
// now it is not - that's part of the system's code
Entities.With(query).ForEach((Entity entity, ref Translation translation, ref Rotation rotation) =>
{
float3 tmpTranslation = translation.Value;
quaternion tmpRotation = rotation.Value;
if (Input.GetKey(KeyCode.W))
// how to retrieve forward vector from the quaternion
tmpTranslation.y += Time.deltaTime * PlayerSpeed;
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
// this always set the same angle
tmpRotation = quaternion.RotateZ(PlayerRotationFactor);
// ECS need this
var newTranslation = new Translation { Value = tmpTranslation };
PostUpdateCommands.SetComponent(entity, newTranslation);
var newRotation = new Rotation { Value = tmpRotation };
PostUpdateCommands.SetComponent(entity, newRotation);
});