- Home /
Collision detection when objects already touch at runtime
How do you detect a collision between two objects at runtime if both are already touching each other at runtime?
For my app, the user rolls a ball on a floor surface. I need to run something when the ball is in any sort of contact with the floor. Since the ball rests on the floor on runtime, my function isn't working. It does work when the ball is jumped and then hits the floor...
I place something similar on my floor object:
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "ball"){
\\some action
}
}
Thanks!
"Since the ball rests on the floor on runtime, my function isn't working. It does work when the ball is jumped and then hits the floor..."
Why don't you keep the ball in the air?
hard to explain, but part of the game requires the ball to be touching the floor
Answer by always_beta · Jun 19, 2012 at 10:34 AM
OnCollisionEnter is called at the moment of two objects collide with each other, and then if the two objects stay together(not bounce back and separated), OnCollisionStay will be called until they are separated, similarly, OnCollisionExit will be called at the moment of two objects separated.
So I guess what you need to do is keep your logic inside OnCollisionStay().
Your answer
Follow this Question
Related Questions
Object detection 2 Answers
how to check if one object is colliding with another 1 Answer
Manually check collision ? 1 Answer
Make invisible wall appear visible upon collision/detection 1 Answer
Tree collision 1 Answer