Skip to content

Commit

Permalink
Rewrote move forces. Also player moves backwards slower
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianMcC committed Feb 6, 2024
1 parent 46faeb6 commit f4950f0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class Player
// Dimensions and stuff
public float Height { get; private set; }
public bool Crouching { get; set; } = false;
private float standingHeight = 1.75f; //? Meter
private float standingHeight = 1.65f; //? Meter
private float crouchingHeight = 1f; //? Meter
private float eyeYFromTopOfHead = 0.15f; //? Meter

// Physics stuff
// TODO: Figure out why the player sinks into the ground (something to do with friction i think)
public float Mass { get; private set; } = 62; //? kilograms
public Vector3 Velocity { get; set; } = Vector3.Zero;
private float frictionCoefficient = 0.1f;

// Movement stuff
public float Speed { get; private set; }
private float crouchForce;
private float walkForce;
private float runForce;
private const float backwardCoefficient = 0.8f;
private const float crouchCoefficient = 0.3f;
private Vector3 forward;
private Vector3 forwardDirection;
private Vector3 right;
Expand Down Expand Up @@ -57,7 +57,6 @@ public Player()
//! I asked Clyde for average horizontal force applied when walking and they said 0.5 - 1.5
walkForce = Mass * 1.2f;
runForce = Mass * 1.5f;
crouchForce = Mass * 0.4f;
}

// Update
Expand Down Expand Up @@ -116,6 +115,7 @@ private void MouseMovement()
private void KeyboardMovement()
{
// Check for if the player wants to crouch
// TODO: Check for if the crouch key is shift, and if it is check for if they are doing `win+shift+s` and don't crouch
if (Raylib.IsKeyDown(SettingsManager.Settings.Crouch))
{
Crouching = true;
Expand All @@ -133,7 +133,16 @@ private void KeyboardMovement()
{
moveForce = runForce;
}
else if (Crouching) moveForce = crouchForce;

// Check for if the player is moving backwards
// TODO: Only check for movement once. Do this another way
if (Raylib.IsKeyDown(SettingsManager.Settings.Backwards))
{
moveForce *= backwardCoefficient;
}

// Check for if the player is crouching
if (Crouching) moveForce *= crouchCoefficient;

Vector3 force = Vector3.Zero;

Expand Down

0 comments on commit f4950f0

Please sign in to comment.