11#pragma once
22
3- #include < glm/glm.hpp>
4- #include < glm/gtc/constants.hpp>
5- #include < glm/trigonometric.hpp>
6-
73#include < application.hpp>
84#include < components/camera.hpp>
95#include < ecs/world.hpp>
6+ #include < glm/glm.hpp>
7+ #include < glm/gtc/constants.hpp>
8+ #include < glm/trigonometric.hpp>
109
1110#include " GLFW/glfw3.h"
1211#include " components/player-movement.hpp"
@@ -21,6 +20,7 @@ namespace gameplay {
2120 class PlayerMovementSystem {
2221 float dashEffectTimer = 0 .0f ;
2322 static constexpr float DASH_EFFECT_DURATION = 0 .3f ;
23+
2424 public:
2525 void update (our::World* world, float deltaTime, our::Application* app) {
2626 PlayerMovementComponent* movement = nullptr ;
@@ -75,7 +75,8 @@ namespace gameplay {
7575 if (movement->isSprinting && glm::length (moveDir) > 0 .001f && movement->slideCooldownTimer <= 0 ) {
7676 movement->isSliding = true ;
7777 movement->slideTimer = movement->slideDuration ;
78- movement->velocity = moveDir * slideStartSpeed; // preserves momentum when sliding and keys are released
78+ movement->velocity =
79+ moveDir * slideStartSpeed; // preserves momentum when sliding and keys are released
7980 movement->isCrouching = false ;
8081 } else {
8182 movement->isCrouching = !movement->isCrouching ;
@@ -94,8 +95,7 @@ namespace gameplay {
9495 } else {
9596 // acts like friction so stopping after key release is not so stiff
9697 movement->velocity *= glm::max (0 .0f , 1 .0f - 10 .0f * deltaTime);
97- if (glm::length (movement->velocity ) < 0 .1f )
98- movement->velocity = glm::vec3 (0 );
98+ if (glm::length (movement->velocity ) < 0 .1f ) movement->velocity = glm::vec3 (0 );
9999 }
100100 }
101101
@@ -131,7 +131,8 @@ namespace gameplay {
131131 playerPosition.y += movement->verticalVelocity * deltaTime;
132132
133133 // jumping always goes back to standing height
134- float minY = movement->verticalVelocity < 0 ? movement->groundLevel + movement->playerHeight : movement->groundLevel + movement->crouchHeight ;
134+ float minY = movement->verticalVelocity < 0 ? movement->groundLevel + movement->playerHeight
135+ : movement->groundLevel + movement->crouchHeight ;
135136 if (playerPosition.y <= minY) {
136137 playerPosition.y = minY;
137138 movement->verticalVelocity = 0 .0f ;
@@ -140,9 +141,8 @@ namespace gameplay {
140141 }
141142
142143 if (movement->isGrounded ) {
143- float targetHeight = (movement->isCrouching || movement->isSliding )
144- ? movement->crouchHeight
145- : movement->playerHeight ;
144+ float targetHeight =
145+ (movement->isCrouching || movement->isSliding ) ? movement->crouchHeight : movement->playerHeight ;
146146 float currentHeight = playerPosition.y - movement->groundLevel ;
147147 float lerpedHeight = currentHeight + (targetHeight - currentHeight) * glm::min (1 .0f , 10 .0f * deltaTime);
148148 playerPosition.y = movement->groundLevel + lerpedHeight;
0 commit comments