- Home /
OnTriggerEnter firing late?
I have a plane with a box collider (+ a rigidbody & set as a trigger) that collides with another plane with a box collider (it's a 2D platformer with 2D graphics).
The thing is, when these two collide at different speeds OnTriggerEnter is fired at different times and I need it to fire as soon as these two touch.
I've made a new scene, throwed in some cubes and a plane.
Added a little snippet to freeze them in place... The higher the speed of the cube, the later the trigger is fired :(
As you can see in the screenshot, the block that had the highest speed is totally OUT of the trigger zone by the time the trigger fires..
How can I make the trigger to fire as soon as they touch?
`void OnTriggerEnter(Collider other) { other.rigidbody.useGravity = false; other.rigidbody.velocity = Vector3.zero; }`
Answer by BiG · Nov 19, 2012 at 02:23 PM
It's a normal behaviour, because a single frame has not an infinitesimal duration. That is, different speeds of the object implies different times on which the collision is detected. Plus, if your plane's collider is very "thin", and the box's velocity is really high, the collision won't be detected at all (that's known as "bullet through paper problem").
If you need your boxes to share the same horizontal (say X) coordinate (that is, having them "in a row"), you could set their X-value (with transform.position.x) as soon as the collision is detected.
The thing is that I need them to BOUNCE off. But, as you said, visually, some blocks go underground first (which could be referred to as a "graphical glitch" or something, because the block does get propelled upwards later).
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
What is Wrong With This Section of my Script? 1 Answer
Why is my exit script not working? 2 Answers
Vehicle Script Debugging 1 Answer
Need a bit of help with my script (about 100 lines) 1 Answer