in short
First time I visited ECS
namespace Game.Player {
unsafe partial struct PlayerMoveSystem : ISystem {
void OnUpdate(ref SystemState state) {
foreach ((RefRW<LocalTransform> transform, RefRO<PlayerData> data, RefRO<PhysicsCollider> collider) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<PlayerData>, RefRO<PhysicsCollider>>()) {
float3 moveDirection = new float3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection *= Input.GetKey(KeyCode.LeftShift) ? data.ValueRO.RunSpeed : data.ValueRO.Speed;
moveDirection *= SystemAPI.Time.DeltaTime;
if (math.lengthsq(moveDirection) < 0.0001f) {
continue;
}
//moveDirection = transform.ValueRO.TransformDirection(moveDirection);
PhysicsWorld physics = SystemAPI.GetSingleton<PhysicsWorldSingleton>().PhysicsWorld;
ColliderCastInput input = new ColliderCastInput {
Collider = collider.ValueRO.ColliderPtr,
Orientation = transform.ValueRO.Rotation,
Start = transform.ValueRO.Position,
End = transform.ValueRO.Position + moveDirection
};
if (physics.CastCollider(input, out ColliderCastHit hit)) {
float3 normal = hit.SurfaceNormal;
float3 remainingMove = moveDirection;
float3 slide = math.normalize(math.projectsafe(remainingMove, math.cross(normal, math.up())));
transform.ValueRW = transform.ValueRO.Translate(slide * math.length(remainingMove) * (1f - hit.Fraction));
Debug.Log($"collision");
} else {
transform.ValueRW = transform.ValueRO.Translate(moveDirection);
}
}
}
}
}```
Why the hell does the player yeet into the void when pressing A or D?