Posted September 13, 2023 by nitsujturtle
v0.7b
Minor Changes:
//EXCERPT FROM PLAYER.CS
deltaTime = Mathf.Clamp(Time.deltaTime, 0, 0.05f);
//Clamps time changes so that frame stutters don't send things flying away
Vector3 attemptedMove = Vector3.zero;
//Prepares an empty Vector3 for movement calculations
Vector3 localVel = transform.InverseTransformDirection((rb.velocity));
//Calculates the current velocity of the player RELATIVE to how the camera sees it
Vector2 normalizedDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;
//Gets movement inputs and turns them into a "input circle" instead of an "input square"
if (((Input.GetAxis("Vertical") > 0) && (localVel.z < maxVel * normalizedDir.y)) || ((Input.GetAxis("Vertical") < 0) && (localVel.z > maxVel * normalizedDir.y)))
//If you are trying to move forward or backwards where you aren't going faster than the limit in that direction
{
attemptedMove += (transform.forward * normalizedDir.y);
//Add the vector to the movement calculation relative to the player
}
if (((Input.GetAxis("Horizontal") > 0) && (localVel.x < maxVel * normalizedDir.x)) || ((Input.GetAxis("Horizontal") < 0) && (localVel.x > maxVel * normalizedDir.x)))
//If you are trying to move right or left where you aren't going faster than the limit in that direction
{
attemptedMove += (transform.right * normalizedDir.x);
//Add the vector to the movement calculation relative to the player
}
if (!grounded)
{
attemptedMove = attemptedMove / 2;
}
//If not touching the ground, your total movement is halved
rb.AddForce(attemptedMove * deltaTime * speed);
//Take the total calculation and apply force accordingly, accounting for framerate, and multiplying by movement speed
I HOPE YOU KNOW THE PAIN I WENT THROUGH TO MAKE MOVING DIAGONAL NOT AN ISSUE
AND IT STILL DOESN'T WORK FOR WHEN YOU MOVE THE CAMERA AT THE SAME TIME AS MOVING
Closing Thoughts: