I´m trying to detect when a rigidbody leaves a collider, and when he does stop the movement. My problem is that the way the units controls the detection with OnCollisionExit it triggers 2 frames after the rigidbody actually leaves the collider. These 2 frames make a big difference.
Is there a way to detect if the rigidbody will leave the collider a frame befor? or even check if it has allready left before rendering that frame?
If its hard to understand I will make an example to show what I mean. Thanks in advance!
Answer by ScroodgeM
Aug 23, 2012 at 09:16 PM
rigidbody's position and leave-collider actions are calculated in physics FixedUpdates. frames (renders to screen) are usually draws a pic with some greater frequency. so, you can see a rigidbody leaving the collider but get not the message about it because this action is still not calculated, just interpolated position for render.
increase FixedUpdate rate (fixed time step) to make these udates more accuracy, or think about custom collision checker
Thanks scroodge didnt realise that physics calculations werent in sync with the frames, lots of things make more sense now :D Changing this improved it considerably.
Answer by mark24
Aug 20, 2012 at 07:23 PM
You could try using using Collision Detection type - Continuous or Continuous Dynamic in the details of the rigidbody. It is supposed to be for high speed objects and may help.
Another option to look into would be to use the Interpolate option - Extrapolate. This means Unity will extrapolate the future position of the rigidbody before it gets there to try and detect collisions more quickly and reliably.
Thanks mark24 these options didnt really make any visible difference for me, maybe the movement is too fast or too slow for this function to be visible.
Answer by turtsmcgurts
Aug 20, 2012 at 07:13 PM
As far as I know, the "Don't Go Through Things" script was written for this purpose.
basically it uses a raytrace to see if the object passed through anything.
Thanks turtsmcgurts, not exactly what I was looking for. This script makes things not go through objects but it was an interesting script I will probably use in the future.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
10 People are following this question.
Is there a way to have rigid bodies collide, but not transfer any force?
jump on collision weird behaviour
Character Controller with rigidbody
Character Controller goes through objects
How to make a rigidbody bullet move through a platform?