- Home /
Tutorial: Space Shooter - 10 Collision not detected?
Let me quickly list the relevant attributes:
Asteroid -> Rigid Body -> No gravity, no Kinematic
'' -> Mesh Collider -> Is Trigger
Player -> Rigid Body -> No Gravity, no Kinematic
'' -> Mesh Collider -> Is Trigger
Player is tagged "Player"
**Scripts**
Destroy By Contact -> Explosion -> explosion_asteroid
'' -> Player Explosion -> explosion_player
Script "DestroyByContact.cs":
using UnityEngine;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Boundary")
{
return;
}
Instantiate(explosion, transform.position, transform.rotation);
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
}
Debug.Log(other.name);
Destroy(other.gameObject);
Destroy(gameObject);
}
}
Note: These settings and scripts match the video exactly, except where I added the Debug.Log.
Whenever I move my player into the asteroid, however, nothing happens. There is no collision detection whatsoever. And yet, when I fire a Bolt
into the asteroid, it works perfectly fine, displaying the explosion and deleting both gameObjects
.
What might be the problem here? I can't be the only one having this problem.
EDIT: Tutorial video here.
Is the asteroid exploding when it hits the player? Define "No collision detection whatsoever". -- I also don't see the mentioned video.
I'm not sure I can be more unambiguous than the absolute statement "no collision detected whatsoever." Neither the Asteroid nor the Player detect any kind of collision. Both carry on with their day as if nothing happened.
Answer by robcbryant · Mar 17, 2014 at 08:13 PM
You can also try unchecking "isTrigger" from the player object. I may be wrong--but I believe two triggers don't interact with one another--I think one of the objects has to be a nontrigger to register the collision. Are your bullets set as "isTrigger" ?
Edit: Two triggers can under certain circumstances-- http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html
There is a cheat sheet table at the bottom explaining the trigger interactions.
I think either your two rigid body objects need to be Kinetic or one of them needs to not be a trigger--probably the player. Have you thought about using a CharacterController instead of a rigid body for your player object? It's a lot simpler to use and control--and you're guaranteed to collide with all triggers using a character controller.
I have tried toggling the "is trigger" a few times. One on, one off. The other on, the first off. Both on. Both off. None of those works. Same with kinematic. I've even done all four iterations of is trigger with all four iterations of kinematic. There has to be some setting somewhere that I clicked by accident. This is frustrating.
Here's a quick test: Are they actually colliding? I'm not being sarcastic--but if it's a 2D game maybe you accidentally set the player ship on a different z/y plane than the asteroids--ie. asteroids and bullets are on z = 0 but player is z = 1;
Check if the collider for the ship is 'checked' on.
If the collisions work with bullets then it's something to do with the ship.
Answer by KacperM · Feb 21, 2015 at 02:53 PM
I had same problem - Mesh Collider check box on Player was disabled. After I enabled it asteroid and ship collide and everything works are it should.
I still have exactly the same problem. Even the finished scene by Unity (Done_$$anonymous$$ain) has the problem of the player not colliding with the asteroids. I am using Unity 5.0.2f1 Personal. $$anonymous$$aybe the project was build on an older version of Unity and has compatibility issues?
Can anyone help?
Thanks!
I just found the error to the my above problem. The 'convex' box was not ticked in mesh collider of the Player, which is not allowed in Unitiy 5.0.2, if the 'is trigger' is ticked. So the solution was simple, just tick the 'convex' box in the mesh collider of the player in prefabs.
Answer by Old_Badger · Jan 07, 2017 at 08:27 PM
I had the same problem using Unity 5.5 for linux. After much searching and clicking make trigger and convex, I found I had the mesh collider for the player deselected. DOH!
Answer by Percefane · Mar 19, 2017 at 05:02 PM
Hello,
I had the same issue. The boxes ticked, in my cases, were in the "Rigidbody" tab, under the "Constraints" and "Freeze Position Y", "Freeze Rotation Y".
When I unticked them, the collision worked!
Hope this can help some of you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613140458im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collision detection not triggering 3 Answers
Yet another Audio on Collision issue 1 Answer
Lerpz tutorial problems 2 Answers
Survival Shooter: Missing Collision Detection? 2 Answers
Parenting tutorial 1 Answer