import {System} from '@/ecs/index.js'; import {normalizeVector} from '@/util/math.js'; export default class ApplyControlMovement extends System { static get priority() { return { before: 'IntegratePhysics', }; } static queries() { return { default: ['Controlled', 'Forces', 'Speed'], }; } tick() { for (const {Controlled, Forces, Speed} of this.select('default')) { if (!Controlled.locked) { const movement = normalizeVector({ x: (Controlled.moveRight - Controlled.moveLeft), y: (Controlled.moveDown - Controlled.moveUp), }); Forces.applyImpulse({ x: Speed.speed * movement.x, y: Speed.speed * movement.y, }); } } } }