- Home /
Collision detection not triggering
Hey all,
I'm going through the 3D platformer tutorial and I ran into some issues regarding the launch pads (invisible boxes that serve only as a collision trigger). I've put all six of them on the map, but find that only two of them work correctly.
I've tried some changes, and through logging I found that the non-working pads did not call onTriggerEnter in the associated script. However, after I've moved it into the open air, they did work. So my guess is that there is a problem with the boxes already colliding with the scenery and thus not triggering the script to launch the player. Is this correct, and if so, how can I tell Unity to ignore the scenery?
And yes, while it would be possible to resize the pads and move them so they don't collide with the rest of the level, this is a learning experience and I'm trying to find the more flexible solution.
EDIT ** I've found the solution. Apparently, I had to lift the box colliders somewhat. I'm still not really sure which two objects should collide, as the rendered player collided with the box outline that the editor showed, but at least this works.
Answer by NukeImYourFather · Aug 12, 2012 at 07:03 PM
Not sure if this will work in your case, but why not try :)
void OnCollisionEnter (Collision collision)
{
if (collision.GameObject.name == "player")
{
print("MAN DOWN, I REPEAT, MAN DOWN!")
}
}
Or something like that, hopefully it will work. But i do not think it will :( Anyways, good luck.
Sadly, this did not work. Oddly enough, replacing onTriggerEnter by onCollisionEnter breaks all launch pads, as onCollisionEnter is never called.
Yeap. Triggers by definition do not collide, and colliders don't trigger. To use OnCollisionEnter you need a non-trigger collider. You could put the OCE function on the actual launch pad object and that might do what you need.
Tried this. For some reason, onCollisionEnter is not called at all. The only difference is that I can now walk on the collider.
Did you replace "player" with the actual name of your object? Did you un-fiddle with collision layers? Collision is a tricky thing, this stuff usually happens to everyone until they get a hang of it x)
Answer by Loius · Aug 12, 2012 at 07:05 PM
You can edit what layers collide with each other in Edit > Project Settings > Physics. Put your pads on, say, the PlayerTriggerable layer, and set that layer to only collide with the Player layer (and of course your player object goes on the Player layer)
This seemed like a logical solution, but unfortunately did not fix the problem. I found that it's not due to this selection being limited to objects that aren't triggers, as disabling collisions on the appropriate layers blocks me from picking up health and fuel cells.
Add those things to the PlayerTriggerable layer as well, and they should work.
Does your player and/or trigger have a rigidbody (or CharacterController) attached?
If you put a Debug.Log in your OnX function, does it print to the Console?
To keep the two threads in one place:
For both onTriggerEnter and onCollisionEnter I've put a Debug.Log at the start of the function. onTriggerEnter works in the previously mentioned two cases, onCollisionEnter never works (whether set a trigger or not). I haven't replaced "player" , because that would only be relevant when the function actually is called.
$$anonymous$$y current layer collisions are set to everything collides with everything, except for Jump Pads, which only collide with the Player.
And yes, my player object has a Character Controller attached.
Answer by I9ball · Aug 16, 2012 at 12:43 PM
Is the trigger check box on the collider component of both objects selected? That has created a similar chaos for me recently. if you uncheck one of them they seem to act normal :)
Your answer
Follow this Question
Related Questions
Can Someone help me with this script? 1 Answer
Game pauses sometimes with OnTriggerEnter 1 Answer
Multiple collisions not working.Plz help 0 Answers
Why would OnTriggerEnter get called, but not OnTriggerExit? 0 Answers
Shooting myself 0 Answers