Collision Detection problems

I am in the realm rush part of the course. I am remaking the game using my own assets i imported from blender. Everything is working fine except that my collisions are not being detected by the enemy.

The enemy is a tank model i made in blender, imported it into unity as a fbx file and added it into the scene. I applied all the enemy scripts and they are working perfectly except the collision detection.

The tank has multiple meshes inside it and i know that is causing problems because when i replaced the tank with a single cube, it was able to detect collisions. How do i fix this

I added a colllider on the parent object but it doesnt work.

Hi Rustic_Dude,

Have you already checked the spelling of the Unity methods in your code?

Which method do you use for the collision detection? Does it match Unity’s rules for detecting collisions and sending collision messages?

Here is the link to the manual:

I used the same collider as i used for a single mesh and it worked on it. Its not working when i have multiple meshes parented to a single collider

What do you mean by “multiple meshes parented to a single collider”? In your screenshot, I can see only one collider mesh: the mesh of the BoxCollider2D component.

Also, I don’t know what “the same collider” is. If it works, there isn’t any problem, is it? If it does not work, it would be great if you could share what you have. Problems are often where we think they are not, so it makes sense to check those things to be on the safe side.

The thing is, I made that tank in blender. I used different cubemeshes to make the top half, bottom half and the wheels.

When I imported it into unity, it got imported as separate meshes parented to a single game object called tank.

I kept my collider on the parent and all my scripts run from there. All the other scripts work but enemy health is not reducing when collision is being detected by the particles coming from current.

So i tried the same thing with a single CUBE. I removed the tank and in its place, I kept a cube with all of the same scrips and it was working. The health was reducing.

So how do I make it work with the tank as well?

The collision mesh does not have anything to do with the mesh you use to visualise your tank. In your screenshot, the green line is the collider mesh. And that mesh belongs to the BoxCollider component. If you want more complex colliders (and decrease the performance of your game), you could use a MeshCollider.

If there is a problem with the asset, check if your tank (and/or its children) have got their own collider components. In that case, they might cause a conflict with the collider on the parent.

One of the objects that collides needs to have a rigid body. In the screen shot, your tank does not. If the projectile also does not, add a rigid body to the tank.

But like i said, collisions are being detected when i am using a singular cube. But its not working on the tank. I will try to upload a gif based on this but i dont know why this is happening. I will try to merge the meshes in blender and reimport the model and see if it fixes the problem

What is a cube? The cube collider? Or a visual cube instead of a visual tank? As I tried to explain above, we have to distinguish between the collider mesh and other meshes. The other meshes are completely irrelevant for the physics simulation. Unity does not care if your tank looks like a cube, a tank, or a cat. The physics simulation does not care either because it just takes the collider mesh and calculates the collisions with it. That’s why we are able to assign a cube mesh, a cat mesh, or a sphere mesh to the MeshCollider even if our game object looks like a tank.

Did you check the children of your tank as suggested in my previous answer?

I figured it out. I don’t know why but my guess was correct.

  1. I added a tank with multiple meshes into the scene and added enemy scripts. Everything was fine but the particle collisions were not being detected.

image

I added a collider to the parent and scaled it to fit the tank.

  1. I removed the tank and added a cube from the add menu in the hierarchy. I positioned it and added the enemy scripts.

All scripts were working perfectly including the health script that didn’t work before on the tank.

  1. Then I tried to merge all the parts of the tank into a single mesh in Unity because i realized that the collisions were not being detected when there were multiple meshes. But failed to do it

  2. I tried to merge all the meshed in Blender itself before importing into unity using Ctrl + Link to link all meshed.

  3. Then i imported into unity and added a box collider and all the enemy scripts. It worked perfectly like intended

Good job! And thanks a lot for sharing how you solved this problem. I’m sure other people have this problem, too, and they’ll be happy to find a solution online. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms