Question by
officialmparts · Mar 10, 2018 at 02:31 AM ·
c#isgrounded
Unity check isgrounded not working
My check if is grounded is not working. All the tags are right. Here is my code:
public Rigidbody rb;
public bool isGrounded;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if(isGrounded)
{
if(Input.GetKey("space"))
{
rb.velocity = new Vector3(0, 10, 0);
}
}
}
void OnCollisionEnter (Collision collisionInfo)
{
if(collisionInfo.collider.tag == "Ground")
{
isGrounded = true;
}
else
{
isGrounded = false;
}
}
Comment
You can follow one of the official tutorials to learn about ground checks in platformers: Unity Learn Site - Creating a Basic Platformer Game
Answer by myzzie · Mar 11, 2018 at 08:41 AM
Setting isGrounded to false in OnCollisionExit would fix your problem, though this is not a good approach towards ground checks.
Your answer
Follow this Question
Related Questions
CapsuleCollider check if grounded 1 Answer
2D-Platformer wrong jumps 0 Answers
How to get isGrounded to work 0 Answers
Clock doesn't stop when reaches 0.0. Can you help me with this. 1 Answer