Skip to content

Commit 8592340

Browse files
committed
fix: decouple input's movement from framerate
1 parent d9baa46 commit 8592340

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Runtime/InputComponent.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ namespace volt::runtime {
1212
uint16_t left { KEY_A };
1313
uint16_t down { KEY_S };
1414
uint16_t right { KEY_D };
15-
float impulse { 4.0f };
15+
float impulse { 250 };
1616
};
1717
}

src/Runtime/InputSystem.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "InputSystem.hh"
22
#include "InputComponent.hh"
33
#include "../Core/LogSystem.hh"
4+
#include "../Core/Timepoint.hh"
45
#include "Rigidbody2DComponent.hh"
56

67
namespace volt::runtime {
@@ -15,10 +16,10 @@ namespace volt::runtime {
1516
void InputSystem::Update(Scene &s) {
1617
s.ForAll<InputComponent, Rigidbody2DComponent>([](auto, auto &i, auto &rb) {
1718
rb.velocity = {0, 0};
18-
if (IsKeyDown(i.left)) rb.velocity.X(rb.velocity.X() - i.impulse);
19-
if (IsKeyDown(i.right)) rb.velocity.X(rb.velocity.X() + i.impulse);
20-
if (IsKeyDown(i.up)) rb.velocity.Y(rb.velocity.Y() - i.impulse);
21-
if (IsKeyDown(i.down)) rb.velocity.Y(rb.velocity.Y() + i.impulse);
19+
if (IsKeyDown(i.left)) rb.velocity.X((rb.velocity.X() - i.impulse) * core::GetDeltaTime());
20+
if (IsKeyDown(i.right)) rb.velocity.X((rb.velocity.X() + i.impulse) * core::GetDeltaTime());
21+
if (IsKeyDown(i.up)) rb.velocity.Y((rb.velocity.Y() - i.impulse) * core::GetDeltaTime());
22+
if (IsKeyDown(i.down)) rb.velocity.Y((rb.velocity.Y() + i.impulse) * core::GetDeltaTime());
2223
});
2324
}
2425
}

0 commit comments

Comments
 (0)