Pretty much it comes down to collision in my game doesnt seem to be working. In my game I have the character moving constantly to the right, as he passes through a cube with its Mesh renderer off I just want it to print “hit” ( at the moment anyway, my plan was for somthing else but since collision wasnt working I just want the debug.log to work).
Both objects have colliders. (tried is trigger on/off on both or either)
Both objects have Rigidbodies (tried without rigidbodies on both or either one and tried is kinematic on both or either)
However when I copypaste it into the script tied with my objects, it doesnt work. I’ve made sure my objects are exactly like the ones he is using in his level.
I’ve read around 10 questions on this site about collision, tried their answers and still nothing. With the limited unity knowledge I have I would assume somehow ive changed some settings or somthing without knowing it. Since I can load up my friends level and the EXACT collision script works. Any help would be greatly appreciated.
Hi there, You need to check the object if your player is colliding with the specific object or not.
For that you need tags or names or something specific. For Example, I am making a shooting game and I want to check if my bullet has collided with the enemy’s collider or not so I will do it this way,
void OnCollisionEnter(collision col)
{
if (col.game.tag == “Enemy”)
{
//Kill the player or play its death animation or replace it with its ragdoll.
}
}
In short, you need to check whether the object is colliding with that specific object or not. If it is not clear, please leave a comment… I’ll try my best to explain in more detail.
Check the layer that the offending object is on.
I had the same sort of ‘it isn’t colliding’ problem and none of the discussion mentioned layers.
The object I was having problems with was assigned to the ‘default’ layer and everything else was on ‘environment’ or ‘terrain’ or ‘player’ and it wasn’t until I asked the question about what layers are used for that I found out that in the Edit->project->physics menu there is a table of layers and you can select those that do or do not collide with each other.
See Unity - Manual: Layer-based collision detection