fix: directional control
This commit is contained in:
parent
14effd2455
commit
62eaa16b28
|
@ -1,5 +1,5 @@
|
|||
import {System} from '@/ecs/index.js';
|
||||
import {HALF_PI} from '@/util/math.js';
|
||||
import {TAU} from '@/util/math.js';
|
||||
|
||||
export default class ControlDirection extends System {
|
||||
|
||||
|
@ -9,18 +9,20 @@ export default class ControlDirection extends System {
|
|||
if (locked) {
|
||||
continue;
|
||||
}
|
||||
if (moveUp > 0) {
|
||||
Direction.direction = HALF_PI * 3;
|
||||
}
|
||||
if (moveDown > 0) {
|
||||
Direction.direction = HALF_PI * 1;
|
||||
}
|
||||
if (moveLeft > 0) {
|
||||
Direction.direction = HALF_PI * 2;
|
||||
}
|
||||
if (moveRight > 0) {
|
||||
Direction.direction = HALF_PI * 0;
|
||||
if (
|
||||
0 === moveRight
|
||||
&& 0 === moveDown
|
||||
&& 0 === moveLeft
|
||||
&& 0 === moveUp
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
Direction.direction = (
|
||||
TAU + Math.atan2(
|
||||
moveDown - moveUp,
|
||||
moveRight - moveLeft,
|
||||
)
|
||||
) % TAU;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user