- Home /
Question by
ReferenceWolf · Jul 03, 2021 at 03:53 PM ·
character controlling
How Do I fix an issue with My Character Not Jumping?
Hi there, I'm making a 2d game in unity. As far as im aware, i have made my code correctly but My character won't jump when i click space
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 1000f;
float horizontalMove = 0f;
bool Jump = false;
bool Crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetKeyDown(KeyCode.Space))
{
Jump = true;
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
Crouch = true;
} else if (Input.GetKeyUp(KeyCode.LeftControl))
{
Crouch = false;
}
}
void FixedUpdate()
{
// move the character
controller.Move(horizontalMove * Time.fixedDeltaTime, Crouch, Jump);
Jump = false;
}
}
This is a screenshot of what i have in unity

note: I dont want the character to be able to be controlled in the air so thats why air control is off
unity-thing.png
(42.0 kB)
Comment
Answer by Dinhtai_cript · Jul 03, 2021 at 04:11 PM
Have you checked "ground check" was close with ground? As I read a CharacterController2D, player have to on ground to jumping or not
yes My ground check is right below my character and as the character moves, the ground check does aswell, so when the player touches the ground, the ground check should be on the ground too
Your answer