Added AssaultDash and all its logic, including a doubletapkey. Doubletapkey could be made more generic.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "Systems/PlayerMovementSystem.h"
|
||||
|
||||
PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker)
|
||||
PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker)
|
||||
: System(world, eventBroker)
|
||||
, PureSystem("Player")
|
||||
{
|
||||
@@ -41,7 +41,9 @@ void PlayerMovementSystem::Update(double dt)
|
||||
|
||||
if (player.HasComponent("Physics")) {
|
||||
ComponentWrapper cPhysics = player["Physics"];
|
||||
|
||||
//Assault Dash Check -
|
||||
//TODO: check if playerclass is assault!
|
||||
assaultDashCheck(controller->Movement(), dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f);
|
||||
glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori));
|
||||
float wishSpeed;
|
||||
if (controller->Crouching()) {
|
||||
@@ -71,12 +73,15 @@ void PlayerMovementSystem::Update(double dt)
|
||||
static float surfaceFriction = 5.f;
|
||||
ImGui::InputFloat("surfaceFriction", &surfaceFriction);
|
||||
float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction;
|
||||
accelerationSpeed = glm::min(accelerationSpeed, addSpeed);
|
||||
//if doubleTapped do Assault Dash - but only boost maximum 50.0f
|
||||
float doubleTapDashBoost = m_AssaultDashDoubleTapped ? 20.0f : 1.0f;
|
||||
accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f);
|
||||
velocity += accelerationSpeed * wishDirection;
|
||||
ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity));
|
||||
}
|
||||
|
||||
if (controller->Jumping() && !controller->Crouching() && velocity.y == 0.f) {
|
||||
//you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air
|
||||
if (!m_PlayerIsDashing && controller->Jumping() && !controller->Crouching() && velocity.y == 0.f) {
|
||||
velocity.y += 4.f;
|
||||
}
|
||||
|
||||
@@ -95,6 +100,7 @@ void PlayerMovementSystem::Update(double dt)
|
||||
ComponentWrapper cAnimation = playerModel["Animation"];
|
||||
|
||||
float movementLength = glm::length(groundVelocity);
|
||||
//TODO: add assault dash animation here
|
||||
if (glm::length(controller->Movement()) > 0.f) {
|
||||
if (controller->Crouching()) {
|
||||
cAnimation["Name"] = "Crouch Walk";
|
||||
@@ -158,3 +164,41 @@ bool PlayerMovementSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
|
||||
return true;
|
||||
}
|
||||
void PlayerMovementSystem::assaultDashCheck(glm::vec3 controllerMovement, double dt, bool isJumping) {
|
||||
m_AssaultDashDoubleTapDeltaTime += dt;
|
||||
m_AssaultDashCoolDownTimer -= dt;
|
||||
//cooldown = m_AssaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work)
|
||||
if (m_AssaultDashCoolDownTimer > (m_AssaultDashCoolDownMaxTimer - 0.25f)) {
|
||||
m_PlayerIsDashing = true;
|
||||
} else {
|
||||
m_PlayerIsDashing = false;
|
||||
}
|
||||
//reset the DoubleTapped state in case we recently doubleTapped
|
||||
if (m_AssaultDashDoubleTapped) {
|
||||
m_AssaultDashDoubleTapped = false;
|
||||
}
|
||||
//Assault Dash logic: tap left or right twice within 0.5sec to activate the doubletap-dash
|
||||
if (controllerMovement.x > 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) {
|
||||
if (m_AssaultDashDoubleTapLastKey != ImGuiKey_RightArrow && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer
|
||||
&& m_AssaultDashTapDirection == AssaultDashDirection::Right && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) {
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer;
|
||||
}
|
||||
m_AssaultDashDoubleTapLastKey = ImGuiKey_RightArrow;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_AssaultDashTapDirection = AssaultDashDirection::Right;
|
||||
} else if (controllerMovement.x < 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) {
|
||||
if (m_AssaultDashDoubleTapLastKey != ImGuiKey_LeftArrow && m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer
|
||||
&& m_AssaultDashTapDirection == AssaultDashDirection::Left && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) {
|
||||
m_AssaultDashDoubleTapped = true;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer;
|
||||
}
|
||||
m_AssaultDashDoubleTapLastKey = ImGuiKey_LeftArrow;
|
||||
m_AssaultDashDoubleTapDeltaTime = 0.f;
|
||||
m_AssaultDashTapDirection = AssaultDashDirection::Left;
|
||||
} else {
|
||||
m_AssaultDashDoubleTapLastKey = ImGuiKey_Escape;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user