29 lines
905 B
C#
29 lines
905 B
C#
using GameCore.ECS;
|
|
using GameCore.ECS.Interfaces;
|
|
using GameCore.Input;
|
|
|
|
namespace GameCore.Movement;
|
|
|
|
public class RotationSystem : ISystem
|
|
{
|
|
private const float MinPitch = -(float)System.Math.PI / 2f;
|
|
private const float MaxPitch = (float)System.Math.PI / 2f;
|
|
|
|
public void Update(World world, float deltaTime)
|
|
{
|
|
var entities = world.GetEntitiesWith<InputStateComponent>();
|
|
foreach (var entity in entities)
|
|
{
|
|
var input = world.GetComponent<InputStateComponent>(entity);
|
|
var rotation = world.GetComponent<RotationComponent>(entity);
|
|
|
|
if (input == null || rotation == null)
|
|
continue;
|
|
|
|
rotation.Rotation.Y += input.LookDirection.Y;
|
|
rotation.Rotation.X += input.LookDirection.X;
|
|
|
|
rotation.Rotation.X = System.Math.Clamp(rotation.Rotation.X, MinPitch, MaxPitch);
|
|
}
|
|
}
|
|
} |