- Home /
How do I stop my sprite from jumping in the air?
I know this has been asked & answered before but those answers don't really work for me as I have way different code. P.S. If anyone knows how to make the sprite be able to double jump please tell me.
Code:
,I know this has been asked and answered before but I have a different code than those people and it's not working for me. P.S. If someone knows how to do this but still make a double jump function please tell me.
My Code:
Answer by sztobar · Mar 16, 2021 at 11:44 AM
Look for "ground-check" in the context of 2d platformer movement. On youtube alone, there are a ton of examples:
They are mostly using raycasting to check if the player is touching the ground, but if you're using Rigidbody2D, the simplest solution would be to get all contacts using rigidBody.GetContacts() and see if there is any ContactPoint2D with normal == Vector2.up
. If there is such contact it means that the player is grounded and we can jump.