37 lines
805 B
JavaScript
37 lines
805 B
JavaScript
import {System} from '@/ecs/index.js';
|
|
|
|
export default class ResetForces extends System {
|
|
|
|
static get priority() {
|
|
return {phase: 'post'};
|
|
}
|
|
|
|
static queries() {
|
|
return {
|
|
default: ['Forces'],
|
|
};
|
|
}
|
|
|
|
tick(elapsed) {
|
|
for (const {Forces} of this.select('default')) {
|
|
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;
|
|
}
|
|
}
|
|
Forces.impulseX = 0;
|
|
Forces.impulseY = 0;
|
|
}
|
|
}
|
|
|
|
}
|