problem with Eteeski Tutorial 1.5 Jumping the right way

I’m following this tutorial and when I try to jump it doesn’t work on the terrain but works on objects with collider. Can you help me?

var acceleracio : float = 5;
var cameraPrincipal : GameObject;
var velocitatMaxima : float = 20;
@HideInInspector
var movimentHoritzontal : Vector2;

var velocitatSalt : float = 20;
@HideInInspector
var grounded : boolean = false;
var inclinacioMaxima : float = 60;

function Update () {

	movimentHoritzontal = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
	
	if(movimentHoritzontal.magnitude > velocitatMaxima){
	
		movimentHoritzontal = movimentHoritzontal.normalized;
		movimentHoritzontal *= velocitatMaxima;
	
	}
	
	rigidbody.velocity.x = movimentHoritzontal.x;
	rigidbody.velocity.z = movimentHoritzontal.y;
	
	transform.rotation = Quaternion.Euler(0, cameraPrincipal.GetComponent(rotacio).rotacioYActual, 0);
	
	rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * acceleracio, 0, Input.GetAxis("Vertical") * acceleracio);
	
	if(Input.GetButtonDown("Jump")  grounded){
		rigidbody.AddRelativeForce(0, velocitatSalt, 0);
	}

}

function OnCollisionStay(collision: Collision){

	for( var contact : ContactPoint in collision.contacts){
		
		if(Vector3.Angle(contact.normal, Vector3.up) > inclinacioMaxima)
			grounded = true;
	
	}

}

function OnCollisionExit(){

	grounded= false;
	
}

thanks

Try increasing your “inclinacioMaxima” to a higher number. That’s stopping you from becoming grounded if the angle of the surface you landed on is more steep than that number.

it works on objects but in a terrain doesn’t work

Try debugging the number of contact.points, and the angle of the collision when colliding with the terrain. Then do the same for the colliders that work, see if anything changes.

I solve the problem. I made a mistake in the code.

thanks Kyle for the help