cant jump in 2d?

i have just watched the 2D Character Controllers video tutorial

and i haven’t had problems working through it until it got to the jump part, my character doesn’t jump when i click space, but the “vspeed” is working because if i walk off the edge of my ground the “vspeed” changes, showing my animation. i don’t know if you know what im talking about so ill just show you the script and hopefully someone can tell me the problem.

**using UnityEngine;
using System.Collections;
public class charactercontrol : MonoBehaviour {

public float maxspeed = 2f;
bool facingright = true;

Animator anim;

bool grounded = false;
public Transform groundcheck;
float groundRadius = 0.2f;
public LayerMask whatisground;
public float jumpforce = 700f;

// Use this for initialization
void Start () {
	anim = GetComponent<Animator> ();
}

// Update is called once per frame
void FixedUpdate () 
{
	
	grounded = Physics2D.OverlapCircle (groundcheck.position, groundRadius, whatisground);
	anim.SetBool ("Ground", grounded); 
	anim.SetFloat ("vspeed", rigidbody2D.velocity.y);
	
	
	float move = Input.GetAxis ("Horizontal");
	
	anim.SetFloat("speed", Mathf.Abs(move));
	
	rigidbody2D.velocity = new Vector2 (move * maxspeed, rigidbody2D.velocity.y);
	
	if (move > 0 &&!facingright)
		Flip();
	else if (move < 0 && facingright)
		Flip ();
}
void update()
{
	//float jump = Input.GetAxis ("Vertical");
	//anim.SetFloat ("jumpforce", Mathf.Abs (jump));
	if (grounded && Input.GetKeyDown(KeyCode.Space))
	{
		anim.SetBool("Ground", false);
		rigidbody2D.AddForce(new Vector2 (0, jumpforce));
	}
}

void Flip()
{
	facingright = !facingright;
	Vector3 theScale = transform.localScale;
	theScale.x *= -1;
	transform.localScale = theScale;
	
}

}**

thanks.

Sorry I was working from my phone earlier and could only see small areas of your code at a time.

Now I am at a PC I have noticed:

  1. Your Update function should have a leading capital i.e. “void update()” should be “void Update()
  2. Your update logic is spilt between FixedUpdate and Update? Is there a reason for this split?

Correcting the spelling of “Update” should fix the immediate problem.

oh dear it was that simple, I’m sorry for wasting your time hahaa all i had to do was put a capital letter on my void Update(), and its split so that the jump key doesnt get missed.

thankyou very much.

i have found that if your sprite has an Animator component, you have to deactivate “apply root motion” because that causes conflict with the 2d physics

,I really don’t know how to thank you very very very dear Kelly, I was stuck in this like more than a week and I really didn’t know what to do to make it jump. you know, I’m kinda very new to unity and it didn’t give me any error either. so I couldn’t find the problem (Capitalizing U in “Update”). You did me a very very very great favor. Thank you so much. GOOOOOOOD LUCK
@username

From: Aref Bikaran/ Kabul Polytechnic University Afghanistan