- Home /
Wrong normals on collision
I've got a strange problem. The thing is, I've got a vehicle (a rigidbody with two box colliders as children) which is moving forward (no turning). Once it hits something from the front (and front only) the player loses.
I did it by checking something like
if(contact.normal.normalized.z > .98f)
and it got me good results when I was using a capsule collider for tests, but now for one reason or another, after changing the model and colliders a bit, I tend to get a normal which is pointing upwards!
Why? What the heck is wrong with my project?
Answer by Fattie · Sep 06, 2012 at 01:47 PM
the best way to check if something hit "the front" and "the front only" is this,
just make another small collider - perhaps a trigger if you prefer - that only sits at the front of the model.
the rest of the colliders will handle ordinary bouncing around, etc.
but when THAT box is triggered, you KNOW it's the front pf the car that is hit.
this is totally ordinary SOP. i was just lookin' at a spacecraft that had a dozen little colliders/triggers here and there for different reasons.
you're .98f thing will never really work because when two unusual shapes of colliders touch, and who knows what is bouncing around where, it's hard to guess the angle of contact.
anyway fortunately it is incredibly easy add a "logic collider" like I describe, far easier than what you are doing.
always think about what you are "actually saying". you're "saying" that if something touches the frone of the car, that's a game over. ok so you clearly need a trigger or collider on the front of the car ! go for it.
I feel stupid for not thinking of that... One question though: how do I check, which of the child car colliders hit? OnCollisionEnter only sends info about the other collider.
edit: Ok, that too, was stupid, found the answer looking through OnCollisonEnter refernce once again.
stupid, are you kidding, like 8 people in the world can figure this stuff out! I just asked someone else! :-) you know why most of the games in the app store are so simple right!
thank God you figured out the answer to your supplementary question, beats me! :O
Damn, that's a big difference in attitude... On most forums people would just get annoyed with my RTF$$anonymous$$ question.
the only person who ever gets annoyed here is $$anonymous$$E, everyone else is super-nice!