[SOLVED] More incline troubles.

Hi everyone, i’m having a problem with my inclines/slopes again, i have them working good when the player is running up a slope and there angle matches the normal of the hill all looks well so does the angle when facing down the hill. My problem is if your travelling down a steep slope the character becomes ungrounded and flies off the hill not too far but its noticable. What i’d like is that the player is stuck to the hill unless the player jumps so that regardless of the change in angle or speed the player walks/runs down the hill.

Anyone have any ideas of how i would achieve this?

Got it half done by appling strong gravity to keep the player grounded. But it looks a little bit shakey when running down, i’ll keep trying though.

I think i have made it worse as it now has that shake or bump to it when traveling up a hill or down a hill anyone got any ideas to remove the slight bumps when traveling up or down inclines?

Yes.

function DownCheck()
{
	var hit : RaycastHit; 
	var slopeAdjust  = 0.0;
	if (Physics.Raycast (transform.position, -Vector3.up, hit)) 
	{
		if (hit.distance < hopHeight) 
		{
			slopeAdjust = hit.distance-controller.height/2;
		}
	}
	
	downSpeed -= slopeAdjust / Time.deltaTime;
}

Run this function before the CharacterController.Move is run in your Update().

Here’s how it works: Chances are you have your downward movement speed set to 0 when the character is on the ground. This way, when he sets foot off the ground, it gives the illusion of gravity pulling him downwards with acceleration.

The problem with this is that if your character steps off a steep slope or step, the next frame he is in midair with a downward velocity of 0, so he’ll bump along down.

This function raycasts downwards from the player’s position every frame. If it hits anything and the distance to the object is less than “hopHeight” (I have a value of 2 on my character) then it makes the variable slopeAdjust equal to the hit distance (taking away half the controller’s height).

In this function downSpeed is my moveDirection.y. I divide the slopeAdjust by deltaTime because CharacterController.Move is almost always multiplied by deltaTime to normalize the framerate…dividing it makes sure that the full adjustment will be made in one frame.

Hope this helped!

Thats exactly what i needed thank you!