- Home /
Question by
unity_jBOSmd1e1IroQw · Nov 03, 2018 at 09:02 PM ·
2d2d game2d sprites
[2D] How to detect if player is grounded on slope?
Player is a 2d circle sprite and I'm using raycast to check if player is on ground. Lenght of ray is 0.51f just enough to reach the collider on ground. But if I'm not on the flat surgace the ray is not long enough to go through collider so I can't jump. I could make the ray longer but then I could jump mulitple times because the ray would still be inside collider.
Comment
Answer by Nocktion · Nov 04, 2018 at 12:40 PM
Try this:
if (Physics.Raycast(transform.position, Vector3.down, isJumping ? 0.51f : 2f, out hit)) {
if (!isJumping) {
//Input handling and logic for jumping
isJumping = true;
}
if (isJumping) {
isJumping = false;
}
//Everything else
}
It think this should work.