I’ve been struggling for a while. When I slide down a slope that has an angle greater than my controller slopeLimit
which is 45f , the slide stops a bit too early so that only 90% of the slide is completed. In the photo the slide is “completed” but it’s not.
// Entire PlayerMovement script
RaycastHit hit;
Vector3 hitPointNormal;
private bool willSlideOnSlopes = true;
public bool isSliding;
void FixedUpdate()
{
RaycastHit hit;
if (controller.isGrounded && Physics.Raycast(transform.position, Vector3.down, out hit, 2f))
{
hitPointNormal = hit.normal;
float slopeAngle = Vector3.Angle(hitPointNormal, Vector3.up);
if (slopeAngle > controller.slopeLimit)
{
isSliding = true;
}
else
{
isSliding = false;
}
}
}
void Update()
{
isGrounded = controller.isGrounded;
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
if (isGrounded)
{
if (willSlideOnSlopes && isSliding)
{
move += new Vector3(hitPointNormal.x, -hitPointNormal.y, hitPointNormal.z) * 2f;
controller.Move(move * Time.deltaTime);
}
}
controller.Move(velocity * Time.deltaTime);
}