diff --git a/include/Engine/Editor/EditorCameraInputController.h b/include/Engine/Editor/EditorCameraInputController.h index 4c139e01..6c5e8b14 100644 --- a/include/Engine/Editor/EditorCameraInputController.h +++ b/include/Engine/Editor/EditorCameraInputController.h @@ -55,11 +55,12 @@ public: } } - if (e.Command == "Sprint") { + //this is just temp here, the sprint ability. it will have a component check later + if (e.Command == "SpecialAbility") { if (e.Value > 0) { - m_SpeedMultiplier *= 2.f; + //m_SpeedMultiplier *= 2.f; } else { - m_SpeedMultiplier /= 2.f; + //m_SpeedMultiplier /= 2.f; } } diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index 1efe4b75..4e964d19 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -4,6 +4,7 @@ #include "../GLM.h" #include "../Core/InputController.h" #include "../Core/ELockMouse.h" +#include "InputHandler.h" template class FirstPersonInputController : public InputController @@ -48,12 +49,18 @@ protected: //assault dash membervariables double m_AssaultDashDoubleTapDeltaTime = 0.0f; double m_AssaultDashCoolDownTimer = 0.0f; - double m_AssaultDashCoolDownMaxTimer = 3.0f; + double m_AssaultDashCoolDownMaxTimer = 2.0f; AssaultDashDirection m_AssaultDashDoubleTapLastKey = AssaultDashDirection::None; const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; - AssaultDashDirection m_AssaultDashTapDirection = AssaultDashDirection::None; + std::string m_AssaultDashTapDirection = ""; bool m_AssaultDashDoubleTapped = false; bool m_PlayerIsDashing = false; + bool m_ShiftDashing = true; + bool m_ValidDoubleTap = false; + + //specialabilitys + bool m_MovementKeyDown = false; + bool m_SpecialAbilityKeyDown = false; EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -125,6 +132,22 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } } + if (e.Command == "Forward" || e.Command == "Right") { + //if value = 0 then you have just released this key + if (e.Value > 0 || e.Value < 0) { + m_MovementKeyDown = true; + //if you pressed the same key within m_AssaultDashDoubleTapSensitivityTimer then you have doubletapped it + if (m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer && m_AssaultDashTapDirection == e.Command) { + m_ValidDoubleTap = true; + } + } else { + m_MovementKeyDown = false; + //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer + m_AssaultDashTapDirection = e.Command; + m_AssaultDashDoubleTapDeltaTime = 0.f; + } + } + if (e.Command == "Jump") { m_Jumping = e.Value > 0; } @@ -133,6 +156,19 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm m_Crouching = e.Value > 0; } + if (e.Command == "SpecialAbility") { + if (e.Value > 0) { + m_SpecialAbilityKeyDown = true; + } else { + m_SpecialAbilityKeyDown = false; + } + } + if (m_SpecialAbilityKeyDown && m_MovementKeyDown) { + m_ShiftDashing = true; + } else { + m_ShiftDashing = false; + } + return true; } @@ -152,7 +188,6 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou template void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping) { - auto controllerMovement = Movement(); m_AssaultDashDoubleTapDeltaTime += dt; m_AssaultDashCoolDownTimer -= dt; //cooldown = m_AssaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) @@ -161,34 +196,43 @@ void FirstPersonInputController::AssaultDashCheck(double dt, bool } else { m_PlayerIsDashing = false; } - //reset the DoubleTapped state in case we recently doubleTapped + + //dashing with shift + if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { + //player is dashing with shift + //the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in! + m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + //moving to the side has priority + return; + } + + //dashing with doubletap - check if doubletap to dash enabled + if (ResourceManager::Load("Input.ini")->Get("Keyboard.DoubleTapToDash", false)) { + return; + } + + //reset the DoubleTapped state in case we recently doubleTapped (doubletap will only happen during 1 frame) 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 != AssaultDashDirection::Right && 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 = AssaultDashDirection::Right; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashTapDirection = AssaultDashDirection::Right; - } else if (controllerMovement.x < 0 && controllerMovement.y == 0.f && controllerMovement.z == 0.f) { - if (m_AssaultDashDoubleTapLastKey != AssaultDashDirection::Left && 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 = AssaultDashDirection::Left; - m_AssaultDashDoubleTapDeltaTime = 0.f; - m_AssaultDashTapDirection = AssaultDashDirection::Left; - } else { - m_AssaultDashDoubleTapLastKey = AssaultDashDirection::None; + + //check if we have received a valid doubletap + if (!m_ValidDoubleTap) { + return; } + m_ValidDoubleTap = false; + + if (!(m_AssaultDashCoolDownTimer <= 0.0f && !isJumping)) { + //if we cant dash at the moment, then just reset the tap-sensitivity-timer + m_AssaultDashDoubleTapDeltaTime = 0.f; + return; + } + //ok, we have a valid tap, lets do it + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashCoolDownTimer = m_AssaultDashCoolDownMaxTimer; } #endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index bb1fd770..17278f14 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -30,4 +30,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/Dash.xml b/resources/Schema/Components/Dash.xml new file mode 100644 index 00000000..084f9620 --- /dev/null +++ b/resources/Schema/Components/Dash.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/resources/Schema/Components/Dash.xsd b/resources/Schema/Components/Dash.xsd new file mode 100644 index 00000000..68b64b0c --- /dev/null +++ b/resources/Schema/Components/Dash.xsd @@ -0,0 +1,18 @@ + + + + + + + + A dash component for one of the classes + + + + + Yada + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index d365c0ee..3029e9f7 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -6,6 +6,7 @@ + diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 70bbafb0..4fe3da2d 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -43,8 +43,14 @@ void PlayerMovementSystem::Update(double dt) ComponentWrapper cPhysics = player["Physics"]; //Assault Dash Check - //TODO: check if playerclass is assault! - controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f); + if (player.HasComponent("Dash")) { + controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f); + } glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); + //this makes sure you can only dash in the 4 directions: forw,backw,left,right + if (controller->AssaultDashDoubleTapped() && controller->Movement().z != 0 && controller->Movement().x != 0) { + wishDirection = glm::vec3(controller->Movement().x, 0, 0)* glm::inverse(glm::quat(ori)); + } float wishSpeed; if (controller->Crouching()) { wishSpeed = playerCrouchSpeed; @@ -74,7 +80,7 @@ void PlayerMovementSystem::Update(double dt) ImGui::InputFloat("surfaceFriction", &surfaceFriction); float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction; //if doubleTapped do Assault Dash - but only boost maximum 50.0f - float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 20.0f : 1.0f; + float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.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)); @@ -84,8 +90,7 @@ void PlayerMovementSystem::Update(double dt) if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { if (velocity.y == 0.f) { controller->SetDoubleJumping(false); - } - else { + } else { controller->SetDoubleJumping(true); } velocity.y += 4.f;