- Home /
Confusion with collision detection
I'm having a little trouble understanding how the collision detection works. Why is it that I have to put isFalling = true; Since the object is not touching anything why would it just ignore that information unless I put isFalling = true;
if(Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
function OnCollisionStay ()
{
isFalling = false;
}
Answer by Fox-Handler · May 02, 2014 at 10:54 AM
I'm going to try and answer my own question. I'm assuming that from the start that the script is "Assuming" that the object is always in space. So it checks to see if the conditions are met and if the object is indeed on the ground then it executes the code. If you push the button again while its in the air, then it will not do anything because the condition was not met. It just goes back to its default value from the beginning that the ball was floating in space. Sry if this question seemed somewhat unreasonable. It's just that it didn't click.
private var onGround = false;
if(Input.GetKeyDown(KeyCode.W) && OnGround == True)
{
rigidbody.velocity.y = jumpHeight;
}
function OnCollisionStay ()
{
onGround = true;
}
Your answer
Follow this Question
Related Questions
Ignore Collision In Physics settings, Doesn't Work?? 1 Answer
How to ignore collisions between two objects but still get the notification? 3 Answers
How to ignore the collision between the character and object in the doodle jump game? 1 Answer
Limit the collision solver's force 1 Answer
Disabling lights collision 2 Answers