- Home /
Why won't my character jump,How do I make my character jump?
I was watching a tutorial on 2D movement and all was good until he started to jump, i had the exact same code as his yet his character jumps and mine doesn't. Does anyone have any answers? Here is my code
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
void FixedUpdate ()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
} ,I was watching a tutorial by Brackeys on 2D movement but it stopped working after i got to a certain part, his character seemed to jump whilst mine didn't. Does anybody know any answers? Here's my code
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
void FixedUpdate ()
{
// Move our character
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
If you are beginner its not the best tutorial to follow. It uses premade scripts and doesnt explain anything about movement. But if you want to stick to it first we need screenshots of your player rigidbody in inspector view. If not check this tutorial, seems better : https://www.youtube.com/watch?v=QGDeafTx5ug