A little bit of help with jump
so i have been trying to make my rigidbody jump,problem is that it only jumps once then it won't execute the action.
Here is the code
void Start () { ground = true;
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Space) && ground == true) {
rb.AddForce (Vector2.up * Jumpforce);
ground = false;
}
if (Input.GetKey (KeyCode.D)) {
rb.AddForce (Vector2.right * speed);
}
}
void OnCollision2DEnter(Collision2D col){
if (col.gameObject.tag == "Ground") {
ground = true;
}
}
void OnCollision2DExit(Collision2D coly){
if (coly.gameObject.tag != "Ground") {
ground = false;
}
}
}
Why have you got OnCollision2DExit checking for things not tagged as Ground? That means if anything collides with your player he is going to be unable to jump even if he is standing on the ground.
Add a debug into OnCollision2DEnter under the tag check to see if it is actually working when the player hits the ground. Since that is the only thing setting ground back to true either that isn't working or OnCollision2DExit is setting it back to false immediately because it is hitting something else too.
Answer by $$anonymous$$ · Apr 10, 2016 at 06:31 AM
I made a simple tut here about jump
https://www.youtube.com/watch?v=tEOZrHTpjTk&list=PL9dzgguwvkSmWJx3yanDKMr24GkHq7pjI∈dex=7
Pls subscribe
Answer by onic2999 · Apr 25, 2016 at 03:04 PM
For anyone that is looking at this post,I've found a workaround
void OnCollisionExit2D (Collision2D coly)
{
grounded = false;
}
void OnCollisionEnter2D (Collision2D cols)
{
grounded = true;
this works for my case,but if there is any wall or any other collider,with this script your object will be allowed to make a second jump.Hopefully this will help others