3rd person animations idle bug fixed

This commit is contained in:
viktorljung
2016-03-12 15:47:19 +01:00
parent 060585a388
commit 0b26f23188
8 changed files with 67 additions and 153 deletions
@@ -163,6 +163,7 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
aeb.Duration = 0.1; aeb.Duration = 0.1;
aeb.NodeName = "Run"; aeb.NodeName = "Run";
aeb.RootNode = firstPersonModel; aeb.RootNode = firstPersonModel;
aeb.SingleLevelBlend = true;
aeb.Start = true; aeb.Start = true;
m_EventBroker->Publish(aeb); m_EventBroker->Publish(aeb);
} }
@@ -172,6 +173,7 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
aeb.Duration = 0.1; aeb.Duration = 0.1;
aeb.NodeName = "Run"; aeb.NodeName = "Run";
aeb.RootNode = firstPersonModel; aeb.RootNode = firstPersonModel;
aeb.SingleLevelBlend = true;
aeb.Start = true; aeb.Start = true;
aeb.Reverse = true; aeb.Reverse = true;
m_EventBroker->Publish(aeb); m_EventBroker->Publish(aeb);
@@ -211,10 +213,10 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
} }
} }
//Animation if (m_PlayerEntity.Valid()) {
if (glm::length2(m_Movement) < 0.25f) { glm::vec2 movementXZ = glm::vec2(m_Movement.x, m_Movement.z);
//Blend to Idle if (glm::length(movementXZ) < 0.1f) {
if (m_PlayerEntity.Valid()) { //Blend to Idle
EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel");
if (playerModel.Valid()) { if (playerModel.Valid()) {
Events::AutoAnimationBlend aeb; Events::AutoAnimationBlend aeb;
@@ -233,10 +235,8 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
aeb.Start = true; aeb.Start = true;
m_EventBroker->Publish(aeb); m_EventBroker->Publish(aeb);
} }
} } else {
} else { //Blend to movement
//Blend to movement
if (m_PlayerEntity.Valid()) {
EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel"); EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel");
if (playerModel.Valid()) { if (playerModel.Valid()) {
Events::AutoAnimationBlend aeb; Events::AutoAnimationBlend aeb;
@@ -248,8 +248,7 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
} }
} }
if (glm::length(m_Movement) > 0) {
if (glm::length2(m_Movement) > 0) {
m_Movement = glm::normalize(m_Movement); m_Movement = glm::normalize(m_Movement);
//Animation //Animation
+1 -2
View File
@@ -49,9 +49,7 @@ public:
next = next->Child[0]; next = next->Child[0];
} }
} }
return next; return next;
} }
}; };
@@ -82,6 +80,7 @@ public:
BlendTree::Node* FirstCommonParent(Node* node1, Node* node2); BlendTree::Node* FirstCommonParent(Node* node1, Node* node2);
EntityWrapper GetSubTreeRoot(std::string nodeName); EntityWrapper GetSubTreeRoot(std::string nodeName);
std::vector<EntityWrapper> GetSubTreeRoots(std::string nodeName);
std::vector<EntityWrapper> GetSingleLevelRoots(std::string name); std::vector<EntityWrapper> GetSingleLevelRoots(std::string name);
std::vector<EntityWrapper> GetEntitesByName(std::string name); std::vector<EntityWrapper> GetEntitesByName(std::string name);
+24 -70
View File
@@ -583,8 +583,8 @@
<EntityFile>Schema/Entities/WeaponAssaultBlueWorld.xml</EntityFile> <EntityFile>Schema/Entities/WeaponAssaultBlueWorld.xml</EntityFile>
</c:Spawner> </c:Spawner>
<c:Transform> <c:Transform>
<Position X="0.128669754" Y="1.08486295" Z="-0.361068189"/> <Position X="0.128669813" Y="1.08486295" Z="-0.361068189"/>
<Orientation X="-0.0353791788" Y="-0.0854677409" Z="0.133094966"/> <Orientation X="-0.0353792347" Y="-0.0854677409" Z="0.133094937"/>
</c:Transform> </c:Transform>
<c:WeaponAttachment> <c:WeaponAttachment>
<Weapon>AssaultWeapon</Weapon> <Weapon>AssaultWeapon</Weapon>
@@ -604,8 +604,8 @@
<EntityFile>Schema/Entities/SidearmWeaponBlueWorld.xml</EntityFile> <EntityFile>Schema/Entities/SidearmWeaponBlueWorld.xml</EntityFile>
</c:Spawner> </c:Spawner>
<c:Transform> <c:Transform>
<Position X="0.128669754" Y="1.08486295" Z="-0.361068189"/> <Position X="0.128669813" Y="1.08486295" Z="-0.361068189"/>
<Orientation X="-0.0353791788" Y="-0.0854677409" Z="0.133094966"/> <Orientation X="-0.0353792347" Y="-0.0854677409" Z="0.133094937"/>
</c:Transform> </c:Transform>
<c:WeaponAttachment> <c:WeaponAttachment>
<Weapon>SidearmWeapon</Weapon> <Weapon>SidearmWeapon</Weapon>
@@ -959,7 +959,7 @@
<Entity name="WeaponBlend"> <Entity name="WeaponBlend">
<Components> <Components>
<c:BlendAdditive> <c:BlendAdditive>
<Adder>MovementBlend</Adder> <Adder>IdleAssault</Adder>
<Receiver>ActionBlend</Receiver> <Receiver>ActionBlend</Receiver>
</c:BlendAdditive> </c:BlendAdditive>
<c:Transform/> <c:Transform/>
@@ -998,41 +998,17 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="MovementBlend2"> <Entity name="IdleAssault">
<Components> <Components>
<c:Blend> <c:Animation>
<Pose1>Idle</Pose1> <AnimationName>IdleAssaultRifleU</AnimationName>
<Pose2>Run</Pose2> <Time>1.9871198993639698</Time>
<Weight>0</Weight> <Play>true</Play>
</c:Blend> <Additive>true</Additive>
</c:Animation>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children/>
<Entity name="Run">
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>1.9871198993639698</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>1.9871198993639698</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
@@ -1063,44 +1039,12 @@
<Entity name="WeaponBlend"> <Entity name="WeaponBlend">
<Components> <Components>
<c:BlendAdditive> <c:BlendAdditive>
<Adder>MovementBlend2</Adder> <Adder>IdleSidearm</Adder>
<Receiver>ActionBlend</Receiver> <Receiver>ActionBlend</Receiver>
</c:BlendAdditive> </c:BlendAdditive>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children>
<Entity name="MovementBlend2">
<Components>
<c:Blend>
<Pose1>Idle</Pose1>
<Pose2>Run</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>IdleSecWepU</AnimationName>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Run">
<Components>
<c:Animation>
<AnimationName>IdleSecWepU</AnimationName>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="ActionBlend"> <Entity name="ActionBlend">
<Components> <Components>
<c:Blend> <c:Blend>
@@ -1133,6 +1077,16 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="IdleSidearm">
<Components>
<c:Animation>
<AnimationName>IdleSecWepU</AnimationName>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Aim"> <Entity name="Aim">
@@ -857,48 +857,12 @@
<Entity name="WeaponBlend"> <Entity name="WeaponBlend">
<Components> <Components>
<c:BlendAdditive> <c:BlendAdditive>
<Adder>MovementBlend2</Adder> <Adder>IdleDefender</Adder>
<Receiver>FinalBlend</Receiver> <Receiver>FinalBlend</Receiver>
</c:BlendAdditive> </c:BlendAdditive>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children>
<Entity name="MovementBlend2">
<Components>
<c:Blend>
<Pose1>Idle</Pose1>
<Pose2>Run</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Run">
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>0.74083502154680936</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>0.74083502154680936</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="FinalBlend"> <Entity name="FinalBlend">
<Components> <Components>
<c:Blend> <c:Blend>
@@ -980,6 +944,18 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="IdleDefender">
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>0.74083502154680936</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Aim"> <Entity name="Aim">
@@ -1007,7 +983,7 @@
<Entity name="WeaponBlend"> <Entity name="WeaponBlend">
<Components> <Components>
<c:BlendAdditive> <c:BlendAdditive>
<Adder>MovementBlend2</Adder> <Adder>IdleSidearm</Adder>
<Receiver>ActionBlend</Receiver> <Receiver>ActionBlend</Receiver>
</c:BlendAdditive> </c:BlendAdditive>
<c:Transform/> <c:Transform/>
@@ -1044,36 +1020,15 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="MovementBlend2"> <Entity name="IdleSidearm">
<Components> <Components>
<c:Blend> <c:Animation>
<Pose1>Idle</Pose1> <AnimationName>IdleSecWepU</AnimationName>
<Pose2>Run</Pose2> <Additive>true</Additive>
</c:Blend> </c:Animation>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children> <Children/>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>IdleSecWepU</AnimationName>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Run">
<Components>
<c:Animation>
<AnimationName>IdleSecWepU</AnimationName>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
+9 -3
View File
@@ -127,8 +127,8 @@ void AnimationSystem::UpdateAnimations(double dt)
void AnimationSystem::UpdateWeights(double dt) void AnimationSystem::UpdateWeights(double dt)
{ {
for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) { for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) {
/* LOG_INFO("%s", it->first.Name().c_str()); //LOG_INFO("%s", it->first.Name().c_str());
it->second.PrintQueue();*/ //it->second.PrintQueue();
if(it->second.HasActiveBlendJob()) { if(it->second.HasActiveBlendJob()) {
AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob(); AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob();
@@ -158,12 +158,13 @@ void AnimationSystem::UpdateWeights(double dt)
bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e) bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
{ {
if (!e.RootNode.Valid()) { if (!e.RootNode.Valid()) {
LOG_ERROR("%s, RootNode invalid %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
} }
if (!e.RootNode.HasComponent("Model")) { if (!e.RootNode.HasComponent("Model")) {
LOG_ERROR("%s, RootNode has no model %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
} }
@@ -171,11 +172,13 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
try { try {
model = ResourceManager::Load<::Model, true>((std::string)e.RootNode["Model"]["Resource"]); model = ResourceManager::Load<::Model, true>((std::string)e.RootNode["Model"]["Resource"]);
} catch (const std::exception&) { } catch (const std::exception&) {
LOG_ERROR("%s, RootNode model not finished loading %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_RawModel->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
LOG_ERROR("%s, RootNode skeleton invalid %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
} }
@@ -183,6 +186,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
if (skeleton->BlendTrees.find(e.RootNode) != skeleton->BlendTrees.end()) { if (skeleton->BlendTrees.find(e.RootNode) != skeleton->BlendTrees.end()) {
blendTree = skeleton->BlendTrees.at(e.RootNode); blendTree = skeleton->BlendTrees.at(e.RootNode);
} else { } else {
LOG_ERROR("%s, No blendtree was found invalid %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
} }
@@ -193,6 +197,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName); subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName);
if (!subTreeRoot.Valid()) { if (!subTreeRoot.Valid()) {
LOG_ERROR("%s, subTreeRoot invalid", e.NodeName);
return false; return false;
} }
@@ -237,6 +242,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
subTreeRoot = entity; subTreeRoot = entity;
if (!subTreeRoot.Valid()) { if (!subTreeRoot.Valid()) {
LOG_ERROR("%s, subTreeRoot invalid", e.NodeName);
return false; return false;
} }
@@ -24,6 +24,8 @@ void PlayerMovementSystem::Update(double dt)
if (LocalPlayer.Valid()){ if (LocalPlayer.Valid()){
updateVelocity(LocalPlayer, dt); updateVelocity(LocalPlayer, dt);
} }
m_SprintEffectTimer += dt; m_SprintEffectTimer += dt;
if (m_SprintEffectTimer < 0.016f) { if (m_SprintEffectTimer < 0.016f) {
return; return;
@@ -74,7 +74,7 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo&
float animationWeight = glm::min(speed, movementSpeed) / movementSpeed; float animationWeight = glm::min(speed, movementSpeed) / movementSpeed;
EntityWrapper rootNode = wi.FirstPersonEntity; EntityWrapper rootNode = wi.FirstPersonEntity;
if (rootNode.Valid()) { if (rootNode.Valid()) {
EntityWrapper blend = rootNode.FirstChildByName("MovementBlend"); EntityWrapper blend = rootNode.FirstChildByName("MovementBlendAssault");
if (blend.Valid()) { if (blend.Valid()) {
(double&)blend["Blend"]["Weight"] = animationWeight; (double&)blend["Blend"]["Weight"] = animationWeight;
} }
@@ -14,7 +14,6 @@ void SidearmWeaponBehaviour::UpdateComponent(EntityWrapper& entity, ComponentWra
void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) void SidearmWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt)
{ {
CheckAmmo(cWeapon, wi); CheckAmmo(cWeapon, wi);
// Start reloading automatically if at 0 mag ammo // 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; float animationWeight = glm::min(speed, movementSpeed) / movementSpeed;
EntityWrapper rootNode = wi.FirstPersonEntity; EntityWrapper rootNode = wi.FirstPersonEntity;
if (rootNode.Valid()) { if (rootNode.Valid()) {
EntityWrapper blend = rootNode.FirstChildByName("MovementBlend"); EntityWrapper blend = rootNode.FirstChildByName("MovementBlendSidearm");
if (blend.Valid()) { if (blend.Valid()) {
(double&)blend["Blend"]["Weight"] = animationWeight; (double&)blend["Blend"]["Weight"] = animationWeight;
} }