Answer the question
In order to leave comments, you need to log in
Why is jump not working in Unity 2D?
private float speed = 8;
float jumpForce = 15;
private bool isGround = false;
private Rigidbody2D rb;
private SpriteRenderer sprite;
private void FixedUpdate() {
CheckGround();
}
private void Update(){
if (Input.GetButton("Horizontal"))
Run();
if (isGround && Input.GetButton("Jump")) {
Jump();
Debug.Log("Jump");
}
}
private void Awake() {
rb = GetComponent<Rigidbody2D>();
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void Jump() {
rb.AddForce(transform.up * jumpForce);
}
private void CheckGround() {
Collider2D[] collider = Physics2D.OverlapCircleAll(transform.position, 0.3f);
isGround = collider.Length > 1;
Debug.Log("CheckGround");
}
isGround = collider.Length > 1
Answer the question
In order to leave comments, you need to log in
And why does it have to be true? For me, this is not obvious - why if we touch more than 1 collider, then we are on the ground?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question