Reputation: 1183
The player is a wheel with a Circle Collider 2d
which can jump and move when it collides with the ground (isGrounded
variable).
I have another two gameObjets
with Polygon Colliders 2d
that represent the ground and are connected side by side.
The player works perfectly, however when it collides with both ground at the same time the collision no longer works even though the player is still standing on one of the grounds.
The variable isGrounded
becomes false and lose control of the player which will not move or jump.
I am using Unity3d 4.5
public class Wheel : MonoBehaviour {
void OnCollisionExit2D(Collision2D collision){
if(collision.gameObject.tag == "Ground"){
Global.IS_PLAYER_GROUNDED = false;
//Debug.Log("exit");
}
}
void OnCollisionEnter2D(Collision2D collision){
if(collision.gameObject.tag == "Ground"){
Global.IS_PLAYER_GROUNDED = true;
//Debug.Log("enter");
}
}
}
Upvotes: 0
Views: 245
Reputation: 230
Hey can you try to add OnCollisionStay2D(Collision2D coll) {//add exactly what's written in oncollisionenter } I am guessing this should help not that sure though if it doesn't ill try and think of another way for you
Upvotes: 1