rigidbody2d.velocity isn't doing anything.

Hello, my character is supposed to be able to jump with a rigidbody.velocity script. I have a rigidbody component for character, but it still won’t do anything. Also the console shows no errors. What is wrong?

//jumping

 if(canJump == true){
rigidbody2D.velocity.y =10;
Debug.Log("This Shows up")


}
}



 function OnCollisionStay2D(coll: Collision2D) {
 	
 	if(coll.gameObject.tag == "Terrain" && Input.GetKeyDown(KeyCode.W)){
 canJump = true;
 	
 
 }
 else{
 	canJump = false;
 }
 }

I’m pressing “w” , and the log shows up, but my character does not jump. Please help, this has been stumping me for the past few days.

UPDATE UPDATE

The programming part look’s like it has no problems. Here’s my project so you can see.

https://www.mediafire.com/?ro0rmr0lx28epgo

A and D - left/right
W - Should make you jump if we get the problem figured out.

Yeah, and I know it’s simple. Just testing out things really.

Thank you.

The problem is that Turtle has an Animator on it with “Apply Root Motion” checked. This means the Animator is constantly updating the position of the turtle to be in a position as defined by the animation it’s playing.

If you uncheck Apply Root Motion from the Animator, your jump code starts working.

I also used rigidbody2d.velocity.y = 10 instead of rigidbody2d.AddForce().

I also found that “Gravity Scale” on the Turtle’s rigidbody was quite strong, so that the Turtle wasn’t able to jump very high, so you’ll probably want to play with that number a bit.

This might sound a little crazy but try

function OnCollisionStay2D(coll: Collision2D) 
{
     if(coll.gameObject.tag == "Terrain" && Input.GetKeyDown(KeyCode.W))
     {
          canJump = true;
          rigidbody2D.velocity.y =10;
     }
}

Let me know if you get something. Also if you don’t mind post your entire code.