PlayerMovementSystem now only updates the velocity of the local player, as it should
This commit is contained in:
@@ -5,14 +5,13 @@
|
|||||||
#include "Input/FirstPersonInputController.h"
|
#include "Input/FirstPersonInputController.h"
|
||||||
#include <imgui/imgui.h>
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
class PlayerMovementSystem : public ImpureSystem, PureSystem
|
class PlayerMovementSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerMovementSystem(SystemParams params);
|
PlayerMovementSystem(SystemParams params);
|
||||||
~PlayerMovementSystem();
|
~PlayerMovementSystem();
|
||||||
|
|
||||||
virtual void Update(double dt) override;
|
virtual void Update(double dt) override;
|
||||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// State
|
// State
|
||||||
@@ -21,4 +20,6 @@ private:
|
|||||||
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
EventRelay<PlayerMovementSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
bool OnPlayerSpawned(Events::PlayerSpawned& e);
|
||||||
|
|
||||||
|
void updateMovementControllers(double dt);
|
||||||
|
void updateVelocity(double dt);
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
|
PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
|
||||||
: System(params)
|
: System(params)
|
||||||
, PureSystem("Player")
|
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
|
||||||
}
|
}
|
||||||
@@ -15,6 +14,12 @@ PlayerMovementSystem::~PlayerMovementSystem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMovementSystem::Update(double dt)
|
void PlayerMovementSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
updateMovementControllers(dt);
|
||||||
|
updateVelocity(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMovementSystem::updateMovementControllers(double dt)
|
||||||
{
|
{
|
||||||
for (auto& kv : m_PlayerInputControllers) {
|
for (auto& kv : m_PlayerInputControllers) {
|
||||||
EntityWrapper player = kv.first;
|
EntityWrapper player = kv.first;
|
||||||
@@ -135,14 +140,16 @@ void PlayerMovementSystem::Update(double dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
|
|
||||||
|
void PlayerMovementSystem::updateVelocity(double dt)
|
||||||
{
|
{
|
||||||
ComponentWrapper& cTransform = entity["Transform"];
|
// Only apply velocity to local player
|
||||||
if (!entity.HasComponent("Physics")) {
|
if (!LocalPlayer.Valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentWrapper& cPhysics = entity["Physics"];
|
ComponentWrapper& cTransform = LocalPlayer["Transform"];
|
||||||
|
ComponentWrapper& cPhysics = LocalPlayer["Physics"];
|
||||||
glm::vec3& velocity = cPhysics["Velocity"];
|
glm::vec3& velocity = cPhysics["Velocity"];
|
||||||
|
|
||||||
// Ground friction
|
// Ground friction
|
||||||
@@ -159,6 +166,7 @@ void PlayerMovementSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
velocity.z *= multiplier;
|
velocity.z *= multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gravity
|
||||||
if (cPhysics["Gravity"]) {
|
if (cPhysics["Gravity"]) {
|
||||||
velocity.y -= 9.82f * (float)dt;
|
velocity.y -= 9.82f * (float)dt;
|
||||||
}
|
}
|
||||||
@@ -171,6 +179,5 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
|||||||
{
|
{
|
||||||
// When a player spawns, create an input controller for them
|
// When a player spawns, create an input controller for them
|
||||||
m_PlayerInputControllers[e.Player] = new FirstPersonInputController<PlayerMovementSystem>(m_EventBroker, e.PlayerID);
|
m_PlayerInputControllers[e.Player] = new FirstPersonInputController<PlayerMovementSystem>(m_EventBroker, e.PlayerID);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user