- Home /
Collision triggered without objects touching - problem
I have a game, where the player is being chased by a monster in a corridor system. If the monster collides with the player, it's game over and it's been working ok so far, but I've decided to add a few more monsters and see how they behave. So I have put the player object on top of my corridors, so it wouldn't collide with my monsters and I could observe their behavior. After about a minute, however, collision has been triggered, even though the monster was halfway across the level. Here's the pic (player's on the left, on top of a white cube, the monster is on the right in a corridor):
Weird thing is, it seems to work fine when the player is inside the corridor system. The problem only arises when he's outside.
Here's my collision code (nothing extraordinary here):
void OnTriggerEnter(Collider other)
{
if(other.tag == "PlayerDamageHandler")
{
//DO STUFF HERE
//FOR DEBUG ONLY
Time.timeScale = 0;
this.gameObject.transform.Rotate(new Vector3(0, 0, 180));
}
}
I've checked all the objects, and there are no other objects with that tag. I'm really stumped on this one, so any help is appreciated.
The logical next step is.. to print the name of the colliding object. Your issue is just the collision getting triggered? or does it also pass the 'tag == "PlayerDamageHandler"' condition? If former, I would expect it could trigger with the wall / corridor and whatnot..
Unfortunately, it passes the check, even though it's pretty far from my player object. I'm gonna run a few more tests and I'll get back to you.
I will. In the meantime, I'll dump some info from my debug log:
Collision with: AdvancedPlayer
Enemy's coords: -5.904749 -2.748328 -14.80869
Player's coords: 0.05429918 4.256039 1.24882
Distance between entities: 18.50446
Player bounds: Center: (0.1, 5.8, 1.2), Extents: (0.8, 1.5, 0.8)
$$anonymous$$onster bounds: Center: (-6.1, -1.4, -15.4), Extents: (1.5, 1.5, 1.5)
$$anonymous$$onster bounds intersect: False
Player bounds intersect: False
So it seems that their bounding boxes aren't even intersecting, yet the collision somehow occurs. I'll try OnCollisionEnter and get back with the results. Thanks for your input so far.
Answer by barker_s · Aug 24, 2013 at 11:00 PM
Ok, I've managed to fix this, although in a rather hacky way.
I used the fact, that during this "phantom collision" there's no points of intersection between my colliders, so I've added another conditional that checks if there's an intersection:
void OnTriggerEnter(Collider other)
{
if(other.tag == "PlayerDamageHandler" && this.collider.bounds.Intersects(other.bounds))
{
//DO STUFF HERE
}
}
It didn't really answer my original question (why would there be a collision event fired without actual collision?), so I'll have to do some more digging about it, but at least I've been able to achieve peace of mind for today ;) .
I had the same problem!! But I couldn't use your solution as "this.collider.bounds.Intersects(other.bounds)" doesn't work anymore
Your answer
Follow this Question
Related Questions
CapsuleCast colliding improperly 2 Answers
3D Particles collision don't work 0 Answers
How do I stop my enemy from falling over? 3 Answers
Collider colliding with itself 1 Answer