x


How to detect precise collision

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!

more ▼

asked Aug 20, 2012 at 07:02 PM

thaiscorpion gravatar image

thaiscorpion
472 41 370 62

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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

more ▼

answered Aug 23, 2012 at 09:16 PM

ScroodgeM gravatar image

ScroodgeM
8.3k 3 11

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.

Aug 30, 2012 at 02:32 PM thaiscorpion
(comments are locked)
10|3000 characters needed characters left

As far as I know, the "Don't Go Through Things" script was written for this purpose.

http://wiki.unity3d.com/index.php?title=DontGoThroughThings

basically it uses a raytrace to see if the object passed through anything.

more ▼

answered Aug 20, 2012 at 07:13 PM

turtsmcgurts gravatar image

turtsmcgurts
53 1 4

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.

Aug 30, 2012 at 02:33 PM thaiscorpion
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Aug 20, 2012 at 07:23 PM

mark24 gravatar image

mark24
67 6 4 6

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.

Aug 30, 2012 at 02:35 PM thaiscorpion
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3964
x2937

asked: Aug 20, 2012 at 07:02 PM

Seen: 1063 times

Last Updated: Aug 30, 2012 at 02:35 PM