public partial class InputMovementSystem : SystemBase
protected override void OnCreate()
//We will use playerForce from the GameSettingsComponent to adjust velocity
RequireSingletonForUpdate<GameSettingsComponent>();
protected override void OnUpdate()
//we must declare our local variables to be able to use them in the .ForEach() below
var gameSettings = GetSingleton<GameSettingsComponent>();
var deltaTime = Time.DeltaTime;
//we will control thrust with WASD"
byte right, left, thrust, reverseThrust;
right = left = thrust = reverseThrust = 0;
//we will use the mouse to change rotation
//we grab "WASD" for thrusting
//we will activate rotating with mouse when the right button is clicked
if (Input.GetMouseButton(1))
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
.ForEach((Entity entity, ref Rotation rotation, ref VelocityComponent velocity) =>
{ //thrust to the right of where the player is facing
velocity.Value += (math.mul(rotation.Value, new float3(1,0,0)).xyz) * gameSettings.playerForce * deltaTime;
{ //thrust to the left of where the player is facing
velocity.Value += (math.mul(rotation.Value, new float3(-1,0,0)).xyz) * gameSettings.playerForce * deltaTime;
{ //thrust forward of where the player is facing
velocity.Value += (math.mul(rotation.Value, new float3(0,0,1)).xyz) * gameSettings.playerForce * deltaTime;
{ //thrust backwards of where the player is facing
velocity.Value += (math.mul(rotation.Value, new float3(0,0,-1)).xyz) * gameSettings.playerForce * deltaTime;
if (mouseX != 0 || mouseY != 0)
//here we have "hardwired" the look speed, we could have included this in the GameSettingsComponent to make it configurable
Quaternion currentQuaternion = rotation.Value;
float yaw = currentQuaternion.eulerAngles.y;
float pitch = currentQuaternion.eulerAngles.x;
yaw += lookSpeedH * mouseX;
pitch -= lookSpeedV * mouseY;
Quaternion newQuaternion = Quaternion.identity;
newQuaternion.eulerAngles = new Vector3(pitch,yaw, 0);
rotation.Value = newQuaternion;