void Move()
{
//If the player is at an angle > 45 and on air, we prevent them from being able to move
//if(Mathf.Abs(angleWithGround) > 45f && !isGrounded)return;
if(gotHurt)return;
if(Mathf.Abs(relativeVel.x) < currentMaxSpeed && !dashing)
{
Debug.Log("Miru Accelerating...");
//To simulate real life acceleration, damping is done based on player's current speed
//We are checking if the player has changed direction or not
//If they changed direction, we add some extra speed for decelerating faster
if(horiz == Mathf.Sign(relativeVel.x) || Mathf.Abs(relativeVel.x) < 0.2f)
{
dampForce = currentSpeedFraction;
// if(Mathf.Sign(dampForce) == -1)
// {
// dampForce -= 0.15f;
// }else
// {
// dampForce += 0.15f;
// }
}else
{
dampForce = currentSpeedFraction * decelerationSpeed;
}
//If the player is on a slope, depending upon how steep it is, a damping multiplier is calculated
angleMultiplier = (Mathf.Sin(angleWithGround * Mathf.Deg2Rad));
//If player trying to go downhill, we add extra acceleration boost
//If player is going uphill, we can reduce the slowness
if((horiz == relativeGravityXDirection && horiz != 0) || horiz == 0)
{
angleMultiplier *= downHillGravityMultiplier;
}else
{
angleMultiplier *= -upHillGravityMultiplier;
}
if(!isGrounded)
{
slopeGravityForce = 0f;
}else
{
slopeGravityForce = angleMultiplier * Time.deltaTime;
}
float movementForce = accel * dampForce * Time.deltaTime;
//Extra speed if on slopes, normal if normal ground
if(isGrounded && angleWithGround != 0f)
{
rb.AddForce(transform.right * movementForce + transform.right * slopeGravityForce);
}else
{
rb.AddForce(transform.right * movementForce);
}
}
}