- Home /
Question by
mirkojpn · Apr 10, 2018 at 06:04 AM ·
collidercollider2dcollision2d
Player jump only once
Hello everyone!
what i'm trying to do is just make my Player jump once, the code that i wrote is the following :
public class PlayerControllerWalk : MonoBehaviour {
public float forceSpeed;
public Rigidbody2D rb2D;
public float jumpForce;
public float xForce;
bool isGrounded;
// Use this for initialization
void Start () {
isGrounded = true;
rb2D = GetComponent<Rigidbody2D>();
}
void Update () {
jump();
}
void FixedUpdate () {
transform.position += Vector3.right * forceSpeed * Time.deltaTime;
}
void jump() {
if (Input.GetMouseButtonDown (0)&& isGrounded){
rb2D.velocity += jumpForce * Vector2.up;
rb2D.velocity += xForce * Vector2.right;
isGrounded = false;
}
}
void OnCollisionEnter2D (Collider2D cl) {
if(cl.tag == "ground" && isGrounded == false) {
isGrounded = true;
}
}
}
but i can't jump again when hit the ground..
Comment
It looks fine to me. $$anonymous$$ake sure everythign has the correct tags. Capitalisation counts.
Best Answer
Answer by sean244 · Apr 10, 2018 at 06:39 AM
It's because you wrote Collider2D instead of Collision2D. Also, you wrote cl.tag instead of cl.gameObject.tag
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D working, OnColliderEnter2D not working 1 Answer
Collision detection problem 0 Answers
How do I make a bridge in game over an existing collision? 0 Answers
How to set collision for an object with specific collider size? 3 Answers
Weird ContactPoint2D on two BoxCollider2D collision 0 Answers