From c1f5cf65a7211ea1029084e48d68f8066ed53630 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Fri, 4 Mar 2016 09:39:16 +0100 Subject: [PATCH] Movement animations --- .../Engine/Input/FirstPersonInputController.h | 13 +- resources/Schema/Entities/Player.xml | 16 +- src/Game/Systems/PlayerMovementSystem.cpp | 139 ++++++++++++------ 3 files changed, 117 insertions(+), 51 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 2c7013e4..00f36ac7 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -129,14 +129,23 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm if (val > 0) { Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; - aeb.NodeName = "Run"; + + if(m_Crouching) { + aeb.NodeName = "Walk"; + } else { + aeb.NodeName = "Run"; + } aeb.RootNode = playerModel; aeb.Start = true; m_EventBroker->Publish(aeb); } else if (val < 0) { Events::AutoAnimationBlend aeb; aeb.Duration = 0.1; - aeb.NodeName = "Run"; + if (m_Crouching) { + aeb.NodeName = "Walk"; + } else { + aeb.NodeName = "Run"; + } aeb.RootNode = playerModel; aeb.Start = true; aeb.Reverse = true; diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 4ff512ac..475acf78 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -894,11 +894,11 @@ - + - StrafeLeftF - + StrafeRightF + 1 true @@ -906,11 +906,11 @@ - + - StrafeRightF - + StrafeLeftF + 1 true @@ -1022,7 +1022,7 @@ DashLeftF - 3 + 2 false @@ -1034,7 +1034,7 @@ DashRightF - 3 + 2 false diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 8fddbe96..3d897bf7 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -343,52 +343,109 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e) EntityWrapper dashEffect = entityFile->MergeInto(m_World); EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); -/* - auto playerEntityModel = playerModel["Model"]; - + for (auto& kv : m_PlayerInputControllers) { + EntityWrapper player = kv.first; + auto& controller = kv.second; - if (player.HasComponent("Physics")) { - glm::vec3 velocity = (glm::vec3)player["Physics"]["Velocity"]; - - glm::vec2 direction = glm::vec2(velocity.x, velocity.z); - - std::string DashName = ""; - if (glm::abs(direction.x) > glm::abs(direction.y)) { - if(glm::sign(direction.x) > 0) { - DashName = "DashRight"; - } else { - DashName = "DashLeft"; - } - } else { - if (glm::sign(direction.y) > 0) { - DashName = "DashForward"; - } else { - DashName = "DashBackward"; - } + if (!player.Valid()) { + continue; } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.1; - aeb.NodeName = DashName; - aeb.RootNode = playerModel; - aeb.Restart = true; - aeb.Start = true; - m_EventBroker->Publish(aeb); - } - { - Events::AutoAnimationBlend aeb; - aeb.Duration = 0.3; - aeb.NodeName = "StandCrouchBlend"; - aeb.RootNode = playerModel; - aeb.Delay = 0.3; - aeb.Start = true; - aeb.Restart = false; - aeb.AnimationEntity = playerModel.FirstChildByName(DashName); - m_EventBroker->Publish(aeb); + if (player.Valid()) { + EntityWrapper playerModel = player.FirstChildByName("PlayerModel"); + if (playerModel.Valid()) { + if (glm::abs(controller->Movement().x) > glm::abs(controller->Movement().z)) { + if (controller->Movement().x > 0) { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "DashRight"; + aeb.RootNode = playerModel; + aeb.Restart = true; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandCrouchBlend"; + aeb.RootNode = playerModel; + aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + m_EventBroker->Publish(aeb); + } + } else { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "DashLeft"; + aeb.RootNode = playerModel; + aeb.Restart = true; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandCrouchBlend"; + aeb.RootNode = playerModel; + aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + m_EventBroker->Publish(aeb); + } + } + } else { + if (controller->Movement().z < 0) { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "DashForward"; + aeb.RootNode = playerModel; + aeb.Restart = true; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandCrouchBlend"; + aeb.RootNode = playerModel; + aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + m_EventBroker->Publish(aeb); + } + } else { + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "DashBackward"; + aeb.RootNode = playerModel; + aeb.Restart = true; + aeb.Start = true; + m_EventBroker->Publish(aeb); + } + { + Events::AutoAnimationBlend aeb; + aeb.Duration = 0.3; + aeb.NodeName = "StandCrouchBlend"; + aeb.RootNode = playerModel; + aeb.Delay = -0.3; + aeb.Start = true; + aeb.Restart = false; + aeb.AnimationEntity = playerModel.FirstChildByName("DashForward"); + m_EventBroker->Publish(aeb); + } + } + } + } } } - */ /* auto playerEntityAnimation = playerModel["Animation"];