- Home /
Question by
Le-Capitaine · Jan 23, 2014 at 01:59 PM ·
c#collisionbooleanground detectiononcollisionstay
How can I tell the player is in contact with the ground, within a script associated with the player?
My code goes like this:
private bool canjump;
void OnCollisionStay (Collider other)
{
if (other.gameObject.tag == "ground") canjump = true;
else canjump = false;
}
Tagged "ground" is, well, the ground. I rigged some GUI text to report the state of canjump and no matter what my player (a sphere rigidbody) is in contact with, it always returns false. It does return true when switching the ground/the relevant function to a Trigger, and the footer reports "Script error: OnCollisionStay", thus I suspect that I'm using the wrong function altogether.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613131221im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Changing Boolean on collision 0 Answers
Problem with OnTriggerStay2D function 2 Answers
SpeedBoost not working,My speedBoostTaken variable isn't working, why? 1 Answer
OnCollisionStay is doing nothing. 1 Answer