Dashing now works great both with shift and doubletap. Added Dash Component. Changed default Player.xml to have a Dash Component. Disabled Sprint. You can now disable DoubleTapToDash in Input.Ini. Added command "SpecialAbility".
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../GLM.h"
|
||||
#include "../Core/InputController.h"
|
||||
#include "../Core/ELockMouse.h"
|
||||
#include "InputHandler.h"
|
||||
|
||||
template <typename EventContext>
|
||||
class FirstPersonInputController : public InputController<EventContext>
|
||||
@@ -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<EventContext, Events::LockMouse> m_ELockMouse;
|
||||
bool OnLockMouse(const Events::LockMouse& e);
|
||||
@@ -125,6 +132,22 @@ bool FirstPersonInputController<EventContext>::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<EventContext>::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<EventContext>::OnLockMouse(const Events::LockMou
|
||||
|
||||
template <typename EventContext>
|
||||
void FirstPersonInputController<EventContext>::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<EventContext>::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<ConfigFile>("Input.ini")->Get<bool>("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
|
||||
@@ -30,4 +30,5 @@
|
||||
<xs:include schemaLocation="Components/Fill.xsd"/>
|
||||
<xs:include schemaLocation="Components/Lifetime.xsd"/>
|
||||
<xs:include schemaLocation="Components/HiddenForLocalPlayer.xsd"/>
|
||||
<xs:include schemaLocation="Components/Dash.xsd"/>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Dash xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Dash.xsd">
|
||||
<Something>true</Something>
|
||||
</Dash>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
|
||||
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
|
||||
|
||||
<xs:element name="Dash">
|
||||
<xs:annotation>
|
||||
<xs:documentation>A dash component for one of the classes</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Something" type="t:bool" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Yada</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
@@ -6,6 +6,7 @@
|
||||
<Origin X="0" Y="0.772000015" Z="0"/>
|
||||
<Size X="1" Y="1.60000002" Z="1"/>
|
||||
</c:AABB>
|
||||
<c:Dash/>
|
||||
<c:Collidable/>
|
||||
<c:Health/>
|
||||
<c:Physics>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user