So I’ve been attempting to make it so that my third person controller slides down a slope when it’s deemed too steep (with the slideThreshold variable) and would thus move down it based on the normals of the surface detected. However despite the surface detection it doesn’t quite seem to even move. It gets the normals but nothing happens afterwards.
Here’s the sliding function I’m attempting.
void Slide()
{
if(Grounded)
{
hitNormal = Vector3.zero;
}
Debug.DrawRay(transform.position + transform.up, debug * Vector3.down, Color.red);
if (Physics.Raycast(transform.position + transform.up, debug * Vector3.down, out hitInfo))
{
hitNormal = new Vector3(hitInfo.normal.x, -hitInfo.normal.y, hitInfo.normal.z);
if (Grounded)
{
hitNormal = Vector3.zero;
}
if (hitInfo.normal.y < SlideThreshold)
{
moveVector += hitNormal * slideSpeed;
}
if (hitNormal.magnitude < maxControllableSlideMag)
{
moveVector = hitNormal * slideSpeed;
}
}
}
void Gravity()
{
if (Grounded == false)
{
VerticalVelocity -= gravity * Time.deltaTime;
}
if (Grounded == true && TerminalVelocity < -1)
{
VerticalVelocity = -1;
}
}
Here’s my movement script.
void Movement()
{
if(moveVector.magnitude > 1)
{
moveVector = Vector3.Normalize(moveVector);
}
CharacterCam = Camera.main.transform;
Slide();
camForward = Vector3.Scale(CharacterCam.forward, new Vector3(1, 0, 1)).normalized;
//make the movement Relative to the camera
moveVector = (InputZ * camForward + InputX * CharacterCam.right ).normalized;
//Get movespeed input based on player input
moveVector *= moveSpeed * InputAxis;
//Applies any Vertical movement
moveVector = new Vector3(moveVector.x, VerticalVelocity, moveVector.z);
Gravity();
player.Move(moveVector * Time.deltaTime);
}
And here’s gravity.
void Gravity()
{
if (Grounded == false)
{
VerticalVelocity -= gravity * Time.deltaTime;
}
if (Grounded == true && TerminalVelocity < -1)
{
VerticalVelocity = -1;
}
}
Need anything else? Just ask and I’ll provide