Fixed dash effect to be supported with the new animations using Fade components.
Added bool Loop field in Fade component.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
PlayerMovementSystem::PlayerMovementSystem(SystemParams params)
|
||||
: System(params)
|
||||
, m_SprintEffectTimer(0.f)
|
||||
, m_DashEffectTimer(0.f)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &PlayerMovementSystem::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &PlayerMovementSystem::OnDoubleJump);
|
||||
@@ -24,23 +25,57 @@ void PlayerMovementSystem::Update(double dt)
|
||||
if (LocalPlayer.Valid()){
|
||||
updateVelocity(LocalPlayer, dt);
|
||||
}
|
||||
|
||||
|
||||
m_SprintEffectTimer += dt;
|
||||
if (m_SprintEffectTimer < 0.016f) {
|
||||
//m_SprintEffectTimer += dt;
|
||||
//if (m_SprintEffectTimer < 0.016f) {
|
||||
// return;
|
||||
//}
|
||||
//m_SprintEffectTimer = 0.f;
|
||||
//auto pool = m_World->GetComponents("SprintAbility");
|
||||
//if (pool == nullptr) {
|
||||
// return;
|
||||
//}
|
||||
//for (auto cSprint : *pool) {
|
||||
// if (cSprint.EntityID != LocalPlayer.ID && (bool)cSprint["Active"]) {
|
||||
// // Spawn one afterimage for each player that sprints.
|
||||
// EntityWrapper player(m_World, cSprint.EntityID);
|
||||
// auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/SprintEffect.xml");
|
||||
// EntityWrapper sprintEffect = entityFile->MergeInto(m_World);
|
||||
// auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
// if (!playerModel.Valid()) {
|
||||
// continue;
|
||||
// }
|
||||
// if (!playerModel.HasComponent("Model")) {
|
||||
// continue;
|
||||
// }
|
||||
// if (!playerModel.HasComponent("Animation")) {
|
||||
// continue;
|
||||
// }
|
||||
// auto playerEntityModel = playerModel["Model"];
|
||||
// auto playerEntityAnimation = playerModel["Animation"];
|
||||
// playerEntityModel.Copy(sprintEffect["Model"]);
|
||||
// playerEntityAnimation.Copy(sprintEffect["Animation"]);
|
||||
// sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
|
||||
// ((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f);
|
||||
// sprintEffect["Animation"]["Speed1"] = 0.0;
|
||||
// sprintEffect["Animation"]["Speed2"] = 0.0;
|
||||
// sprintEffect["Animation"]["Speed3"] = 0.0;
|
||||
// sprintEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
// sprintEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"];
|
||||
// }
|
||||
//}
|
||||
m_DashEffectTimer += dt;
|
||||
if (m_DashEffectTimer < 0.046f) {
|
||||
return;
|
||||
}
|
||||
m_SprintEffectTimer = 0.f;
|
||||
auto pool = m_World->GetComponents("SprintAbility");
|
||||
m_DashEffectTimer = 0.f;
|
||||
auto pool = m_World->GetComponents("DashAbility");
|
||||
if (pool == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (auto cSprint : *pool) {
|
||||
if (cSprint.EntityID != LocalPlayer.ID && (bool)cSprint["Active"]) {
|
||||
// Spawn one afterimage for each player that sprints.
|
||||
EntityWrapper player(m_World, cSprint.EntityID);
|
||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/SprintEffect.xml");
|
||||
EntityWrapper sprintEffect = entityFile->MergeInto(m_World);
|
||||
for (auto cDash : *pool) {
|
||||
if (cDash.EntityID != LocalPlayer.ID && (double)cDash["CoolDownMaxTimer"] - (double)cDash["CoolDownTimer"] < 0.5) {
|
||||
// Spawn one afterimage for each player that Dashes.
|
||||
EntityWrapper player(m_World, cDash.EntityID);
|
||||
auto playerModel = player.FirstChildByName("PlayerModel");
|
||||
if (!playerModel.Valid()) {
|
||||
continue;
|
||||
@@ -48,20 +83,20 @@ void PlayerMovementSystem::Update(double dt)
|
||||
if (!playerModel.HasComponent("Model")) {
|
||||
continue;
|
||||
}
|
||||
if (!playerModel.HasComponent("Animation")) {
|
||||
continue;
|
||||
}
|
||||
auto playerEntityModel = playerModel["Model"];
|
||||
auto playerEntityAnimation = playerModel["Animation"];
|
||||
playerEntityModel.Copy(sprintEffect["Model"]);
|
||||
playerEntityAnimation.Copy(sprintEffect["Animation"]);
|
||||
sprintEffect["ExplosionEffect"]["EndColor"] = (glm::vec4)playerEntityModel["Color"];
|
||||
((Field<glm::vec4>)sprintEffect["ExplosionEffect"]["EndColor"]).w(0.f);
|
||||
sprintEffect["Animation"]["Speed1"] = 0.0;
|
||||
sprintEffect["Animation"]["Speed2"] = 0.0;
|
||||
sprintEffect["Animation"]["Speed3"] = 0.0;
|
||||
sprintEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
sprintEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"];
|
||||
EntityWrapper dashEffect = playerModel.Clone();
|
||||
playerEntityModel.Copy(dashEffect["Model"]);
|
||||
for (auto& cAnim : dashEffect.ChildrenWithComponent("Animation")) {
|
||||
cAnim["Animation"]["Play"] = false;
|
||||
}
|
||||
dashEffect.AttachComponent("Lifetime");
|
||||
dashEffect.AttachComponent("Fade");
|
||||
dashEffect["Fade"]["Loop"] = false;
|
||||
dashEffect["Fade"]["FadeTime"] = 0.5;
|
||||
dashEffect["Fade"]["Time"] = (double)dashEffect["Fade"]["FadeTime"];
|
||||
dashEffect["Lifetime"]["Lifetime"] = (double)dashEffect["Fade"]["FadeTime"];
|
||||
dashEffect["Transform"]["Position"] = (glm::vec3)player["Transform"]["Position"];
|
||||
dashEffect["Transform"]["Orientation"] = (glm::vec3)player["Transform"]["Orientation"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user