Hi everyone
I am trying to make a 3D character controller but ran into an issue where my player would slow down going up slopes and would bounce going down. I have come up with a solution I was happy with but it seems to slow down the player any time they move up or down a slope. Basically, rather than driving my player towards transform.forward, I am getting the forward direction based on the current ground normal.
forwardDir = Vector3.ProjectOnPlane(transform.forward, groundNormal);
if (rayGrounded)
{
targetSpeed = (((isRunning) ? runSpeed : walkSpeed) * inputDir.magnitude);
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime));
velocityY += Time.deltaTime * gravity;
velocity = ((forwardDir) * currentSpeed) + (Vector3.up * velocityY) + dashVelocity;
}
else
{
targetSpeed = (((isRunning) ? runSpeed : walkSpeed) * inputDir.magnitude);
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime));
velocityY += Time.deltaTime * gravity;
velocity = ((forwardDir) * currentSpeed) + (Vector3.up * velocityY) + dashVelocity;
}
playerController.Move((velocity * Time.deltaTime));
Any help would be appreciated! This issue has been bugging me all day and im sure its a simple fix.