- Home /
Collision occurring when it should not! Help!
[EDIT]: One more related oddity: I have line renderer showing the trajectory the projectile will take when I shoot it. This trajectory also shows an "X" where it is going to hit and that X faces the normal of that collision point. Interestingly enough, when I point to these "bad areas", the trajectory does SOMETIMES stop there and shows an "X". As if there was a collider there. But when I look at the scene, there is absolutely no collider there (even when selecting everything in the scene with Crtl+A/Command+A).
I have a game where you are constantly throwing things at people. Simple colliders for the characters and the environment as well as the projectiles. The only things with rigid bodies are the projectiles and some small props in the game.
Everything works fine. But after playing the game for a good 10 minutes, random collision start to occur. I throw projectiles and they bounce out of nothing. Or I throw them and they seem to enter some sort of "anti-gravity field" where they freeze mid-air (but continue their rotation). I can pause the game at that point, and when I look at the entire scene, all my colliders seem correct and in their right place. The scene looks perfectly fine. But collision start occurring where they should not. These "bad collision areas" stick around and sometimes seem to be part of the characters. So once these collision areas occur, they don't disappear. The game just gets more and more of those over time until it is unplayable. I say at least some of them seem to be related to the characters, because sometimes when these characters with these bad collision areas tend to push away certain props of the environment when they are nowhere near them.
Even more odd, when I hit these bad areas, sometimes it triggers the OnCollisionEnter methods of multiple characters, who should not be related at all! So lets say I hit this bad collision area which seems to be related to character A, both character A and character B respond to that collision at the same time!
Has anyone experienced anything similar to this? Can anyway shed some light on this because I have run out of ideas.
Thank you so much in advance.
Cheers,
Filipe
do you destroy unneeded colliders, rigidbodies and other physic-relative objects?
also try to watch at your gameplay using profiller - may be some overflows happened
You say that the colliders all seem to be in place but have you checked your Hierarchy tab for spare objects floating around? If you click on one of those you may see un-deleted colliders hovering where you're having trouble.
Also, some of your issues almost sound like they have something to do with parenting. Do you have any scripts that change objects' parent?
I set my projectiles to destroy themselves 3 seconds after they hit anything by doing this on OnCollisionEnter (I do a few checks first and then call this):
transform.parent = null; Destroy(gameObject, 3.0f);
Looking at my hierarchy I don't any left-over projectiles there. They seem to be disappearing as they should. Is there anything in particular I should look for using the profiler? Thank you so much for the help!
look at CPU usage - does it increasing during gameplay and are there any bottlenecks at the moment of your lags occurs
if it does, look for what is overload source
@$$anonymous$$uuskii, All the projectiles are instantiated without any parent. Some projectiles do stick to character, so I do parent those in script to the characters, which I thought was the problem. However, I am not using these projectiles in order to isolate this issue and it still occurs without any parenting change. There are no trailing objects. They seem to be destroyed correctly.
Answer by wmgcata · Jul 23, 2012 at 06:14 PM
I remember myself having this problem before. Seems to me it hasn't got anything to do with your script, but with the collision with other objects. Try to make sure your rockets aren't colliding with anything else when firing them. That's the only tip i could give. There's probably other people who have any other suggestions?
"Seems to me it hasn't got anything to do with your script, but with the collision with other objects." Can you elaborate a bit on this? About collision when firing, prior to firing, the projectile lays on a box collider with a layer "Pullplane" while all projectiles are in a layer "Projectiles". On the Layer Collision $$anonymous$$atrix on Physics preferences, "Pullplane" is set not to collide with anything. It is there only for Touch raycasting to detect where you want to shoot the projectile from.