silphius/app/ecs/systems/reset-forces.js

37 lines
805 B
JavaScript
Raw Normal View History

2024-06-25 10:44:37 -05:00
import {System} from '@/ecs/index.js';
export default class ResetForces extends System {
static get priority() {
2024-06-26 07:41:07 -05:00
return {phase: 'post'};
2024-06-25 10:44:37 -05:00
}
static queries() {
return {
default: ['Forces'],
};
}
2024-07-02 08:05:36 -05:00
tick(elapsed) {
2024-06-26 07:41:07 -05:00
for (const {Forces} of this.select('default')) {
2024-07-02 08:05:36 -05:00
if (0 !== Forces.forceX) {
const factorX = Math.pow(1 - Forces.dampingX, elapsed);
Forces.forceX *= factorX;
if (Math.abs(Forces.forceX) <= 1) {
Forces.forceX = 0;
}
}
if (0 !== Forces.forceY) {
const factorY = Math.pow(1 - Forces.dampingY, elapsed);
Forces.forceY *= factorY;
if (Math.abs(Forces.forceY) <= 1) {
Forces.forceY = 0;
}
}
2024-06-25 10:44:37 -05:00
Forces.impulseX = 0;
Forces.impulseY = 0;
}
}
}