Fix unintuitive movement (random stopping)

Instead of completely stopping on key release, only that specific
movement is stopped
This commit is contained in:
karl 2020-01-07 22:19:15 +01:00
parent 8c6a1d7834
commit 65f0e3367b

View File

@ -28,33 +28,33 @@ class KeyboardMovementSystem : public EntitySystem, public EventSubscriber<Input
if (event.key == GLFW_KEY_W) {
myWorld->each<Movement>([&](Entity *ent, ComponentHandle<Movement> movement) {
if (event.action == GLFW_PRESS) {
movement->moving.z = -1;
movement->moving.z -= 1;
} else if (event.action == GLFW_RELEASE) {
movement->moving.z = 0;
movement->moving.z += 1;
}
});
} else if (event.key == GLFW_KEY_S) {
myWorld->each<Movement>([&](Entity *ent, ComponentHandle<Movement> movement) {
if (event.action == GLFW_PRESS) {
movement->moving.z = 1;
movement->moving.z += 1;
} else if (event.action == GLFW_RELEASE) {
movement->moving.z = 0;
movement->moving.z -= 1;
}
});
} else if (event.key == GLFW_KEY_A) {
myWorld->each<Movement>([&](Entity *ent, ComponentHandle<Movement> movement) {
if (event.action == GLFW_PRESS) {
movement->moving.x = -1;
movement->moving.x -= 1;
} else if (event.action == GLFW_RELEASE) {
movement->moving.x = 0;
movement->moving.x += 1;
}
});
} else if (event.key == GLFW_KEY_D) {
myWorld->each<Movement>([&](Entity *ent, ComponentHandle<Movement> movement) {
if (event.action == GLFW_PRESS) {
movement->moving.x = 1;
movement->moving.x += 1;
} else if (event.action == GLFW_RELEASE) {
movement->moving.x = 0;
movement->moving.x -= 1;
}
});
}