- Home /
Character doesn't fall back down when jumping
I am trying to get my character to jump, but when the character jumps, it moves up about 50px above the ground, and doesn't come back down, and I cannot figure out why this is happening. Here is the code that I am using on the character
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float jumpForce = 100f;
public float groundRadius = 0.2f;
public Transform groundCheck;
public LayerMask whatIsGround;
protected bool jump = false;
public bool grounded = false;
void Update(){
if(Input.GetButtonDown("Jump") && this.grounded){
this.jump = true;
}
}
void FixedUpdate(){
this.grounded = Physics2D.OverlapCircle(this.groundCheck.position, this.groundRadius, this.whatIsGround);
if(this.jump){
rigidbody2D.AddForce(new Vector2(0f, this.jumpForce));
this.jump = false;
}
}
}
Here is the character's settings:
Do you have anything set in the Inspector for the Layer$$anonymous$$ask whatIsGround variable dropdown?
Yes, I have an a layer named ground
which is the ground.
I assume you do not get errors. Can you please check is$$anonymous$$inematic, gravity and mass values of the rigidbody? I can not think of anything else.
@koray1396 I just checked "is$$anonymous$$enematic" and I wasn't even able to jump.
I have updated the question with an image of my characters settings.
Your answer
Follow this Question
Related Questions
Rigidbody2d addforce is weaker at a higher y position. 2 Answers
Jump problem 1 Answer
Use addForce to Jump 1 Answer