From 0b26f23188e38caae27cf69fcdffd1e6aab49394 Mon Sep 17 00:00:00 2001 From: viktorljung Date: Sat, 12 Mar 2016 15:47:19 +0100 Subject: [PATCH] 3rd person animations idle bug fixed --- .../Engine/Input/FirstPersonInputController.h | 19 ++-- include/Engine/Rendering/BlendTree.h | 3 +- .../Schema/Entities/PlayerAssaultBlue.xml | 94 +++++-------------- .../Schema/Entities/PlayerDefenderBlue.xml | 85 ++++------------- src/Engine/Rendering/AnimationSystem.cpp | 12 ++- src/Game/Systems/PlayerMovementSystem.cpp | 2 + .../Systems/Weapon/AssaultWeaponBehaviour.cpp | 2 +- .../Systems/Weapon/SidearmWeaponBehaviour.cpp | 3 +- 8 files changed, 67 insertions(+), 153 deletions(-) diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 30d1f945..68c8a430 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -163,6 +163,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.Duration = 0.1; aeb.NodeName = "Run"; aeb.RootNode = firstPersonModel; + aeb.SingleLevelBlend = true; aeb.Start = true; m_EventBroker->Publish(aeb); } @@ -172,6 +173,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.Duration = 0.1; aeb.NodeName = "Run"; aeb.RootNode = firstPersonModel; + aeb.SingleLevelBlend = true; aeb.Start = true; aeb.Reverse = true; m_EventBroker->Publish(aeb); @@ -211,10 +213,10 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } } - //Animation - if (glm::length2(m_Movement) < 0.25f) { - //Blend to Idle - if (m_PlayerEntity.Valid()) { + if (m_PlayerEntity.Valid()) { + glm::vec2 movementXZ = glm::vec2(m_Movement.x, m_Movement.z); + if (glm::length(movementXZ) < 0.1f) { + //Blend to Idle EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); if (playerModel.Valid()) { Events::AutoAnimationBlend aeb; @@ -233,10 +235,8 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm aeb.Start = true; m_EventBroker->Publish(aeb); } - } - } else { - //Blend to movement - if (m_PlayerEntity.Valid()) { + } else { + //Blend to movement EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); if (playerModel.Valid()) { Events::AutoAnimationBlend aeb; @@ -248,8 +248,7 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } } - - if (glm::length2(m_Movement) > 0) { + if (glm::length(m_Movement) > 0) { m_Movement = glm::normalize(m_Movement); //Animation diff --git a/include/Engine/Rendering/BlendTree.h b/include/Engine/Rendering/BlendTree.h index 502a1cc9..46ea7f0c 100644 --- a/include/Engine/Rendering/BlendTree.h +++ b/include/Engine/Rendering/BlendTree.h @@ -49,9 +49,7 @@ public: next = next->Child[0]; } } - return next; - } }; @@ -82,6 +80,7 @@ public: BlendTree::Node* FirstCommonParent(Node* node1, Node* node2); EntityWrapper GetSubTreeRoot(std::string nodeName); + std::vector GetSubTreeRoots(std::string nodeName); std::vector GetSingleLevelRoots(std::string name); std::vector GetEntitesByName(std::string name); diff --git a/resources/Schema/Entities/PlayerAssaultBlue.xml b/resources/Schema/Entities/PlayerAssaultBlue.xml index 4ca636da..4797ec09 100644 --- a/resources/Schema/Entities/PlayerAssaultBlue.xml +++ b/resources/Schema/Entities/PlayerAssaultBlue.xml @@ -583,8 +583,8 @@ Schema/Entities/WeaponAssaultBlueWorld.xml - - + + AssaultWeapon @@ -604,8 +604,8 @@ Schema/Entities/SidearmWeaponBlueWorld.xml - - + + SidearmWeapon @@ -959,7 +959,7 @@ - MovementBlend + IdleAssault ActionBlend @@ -998,41 +998,17 @@ - + - - Idle - Run - 0 - + + IdleAssaultRifleU + + true + true + - - - - - IdleAssaultRifleU - - true - true - - - - - - - - - IdleAssaultRifleU - - true - true - - - - - - + @@ -1063,44 +1039,12 @@ - MovementBlend2 + IdleSidearm ActionBlend - - - - Idle - Run - 0 - - - - - - - - IdleSecWepU - true - - - - - - - - - IdleSecWepU - true - - - - - - - @@ -1133,6 +1077,16 @@ + + + + IdleSecWepU + true + + + + + diff --git a/resources/Schema/Entities/PlayerDefenderBlue.xml b/resources/Schema/Entities/PlayerDefenderBlue.xml index 5fcc6c64..84324379 100644 --- a/resources/Schema/Entities/PlayerDefenderBlue.xml +++ b/resources/Schema/Entities/PlayerDefenderBlue.xml @@ -857,48 +857,12 @@ - MovementBlend2 + IdleDefender FinalBlend - - - - Idle - Run - 0 - - - - - - - - IdleAssaultRifleU - - true - true - - - - - - - - - IdleAssaultRifleU - - true - true - - - - - - - @@ -980,6 +944,18 @@ + + + + IdleAssaultRifleU + + true + true + + + + + @@ -1007,7 +983,7 @@ - MovementBlend2 + IdleSidearm ActionBlend @@ -1044,36 +1020,15 @@ - + - - Idle - Run - + + IdleSecWepU + true + - - - - - IdleSecWepU - true - - - - - - - - - IdleSecWepU - true - - - - - - + diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index e30c2e9f..3895dc4a 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -127,8 +127,8 @@ void AnimationSystem::UpdateAnimations(double dt) void AnimationSystem::UpdateWeights(double dt) { for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) { - /* LOG_INFO("%s", it->first.Name().c_str()); - it->second.PrintQueue();*/ + //LOG_INFO("%s", it->first.Name().c_str()); + //it->second.PrintQueue(); if(it->second.HasActiveBlendJob()) { AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob(); @@ -158,12 +158,13 @@ void AnimationSystem::UpdateWeights(double dt) bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) { - if (!e.RootNode.Valid()) { + LOG_ERROR("%s, RootNode invalid %s", e.NodeName, e.RootNode.Name().c_str()); return false; } if (!e.RootNode.HasComponent("Model")) { + LOG_ERROR("%s, RootNode has no model %s", e.NodeName, e.RootNode.Name().c_str()); return false; } @@ -171,11 +172,13 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) try { model = ResourceManager::Load<::Model, true>((std::string)e.RootNode["Model"]["Resource"]); } catch (const std::exception&) { + LOG_ERROR("%s, RootNode model not finished loading %s", e.NodeName, e.RootNode.Name().c_str()); return false; } Skeleton* skeleton = model->m_RawModel->m_Skeleton; if (skeleton == nullptr) { + LOG_ERROR("%s, RootNode skeleton invalid %s", e.NodeName, e.RootNode.Name().c_str()); return false; } @@ -183,6 +186,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) if (skeleton->BlendTrees.find(e.RootNode) != skeleton->BlendTrees.end()) { blendTree = skeleton->BlendTrees.at(e.RootNode); } else { + LOG_ERROR("%s, No blendtree was found invalid %s", e.NodeName, e.RootNode.Name().c_str()); return false; } @@ -193,6 +197,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName); if (!subTreeRoot.Valid()) { + LOG_ERROR("%s, subTreeRoot invalid", e.NodeName); return false; } @@ -237,6 +242,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) subTreeRoot = entity; if (!subTreeRoot.Valid()) { + LOG_ERROR("%s, subTreeRoot invalid", e.NodeName); return false; } diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index b86d4140..51d7bcef 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -24,6 +24,8 @@ void PlayerMovementSystem::Update(double dt) if (LocalPlayer.Valid()){ updateVelocity(LocalPlayer, dt); } + + m_SprintEffectTimer += dt; if (m_SprintEffectTimer < 0.016f) { return; diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp index cf2aa9c5..0662cbaa 100644 --- a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -74,7 +74,7 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& float animationWeight = glm::min(speed, movementSpeed) / movementSpeed; EntityWrapper rootNode = wi.FirstPersonEntity; if (rootNode.Valid()) { - EntityWrapper blend = rootNode.FirstChildByName("MovementBlend"); + EntityWrapper blend = rootNode.FirstChildByName("MovementBlendAssault"); if (blend.Valid()) { (double&)blend["Blend"]["Weight"] = animationWeight; } diff --git a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp index 9c12bb2c..f87f1f81 100644 --- a/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/SidearmWeaponBehaviour.cpp @@ -14,7 +14,6 @@ void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWra void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { - CheckAmmo(cWeapon, wi); // Start reloading automatically if at 0 mag ammo @@ -64,7 +63,7 @@ void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& float animationWeight = glm::min(speed, movementSpeed) / movementSpeed; EntityWrapper rootNode = wi.FirstPersonEntity; if (rootNode.Valid()) { - EntityWrapper blend = rootNode.FirstChildByName("MovementBlend"); + EntityWrapper blend = rootNode.FirstChildByName("MovementBlendSidearm"); if (blend.Valid()) { (double&)blend["Blend"]["Weight"] = animationWeight; }