x


Impossible error

On rare circumstances, when my controller hits a jumping target I'm getting an

IndexOutOfRangeException: Array index is out of range.

error on the following code

private void OnCollisionStay(Collision collision)
{
    var contacts = collision.contacts;
    _contactNormal = contacts[0].normal; // this line
}

and I don't really see how this is possible.

If OnCollisionStay is called, then I assume there should always be collision, therefore I have to be in contact with something.

Obviously I can fixed this by checking for the value, but really want to know if this is just a bug or is there chance under certain circumstances that this could occur.

Cheers

more ▼

asked Jun 23 '11 at 02:37 PM

tertle gravatar image

tertle
1.1k 15 18 33

I tested this in a PC machine with Unity 3.3, and there were always at least one contact point in OnCollisionStay. Maybe it's a bug related to some specific Unity implementation - Mac, iOS, Android, or even PCs with NVidia GPU (if there's a NVidia GPU, the PhysX engine will use it, changing the way physic is evaluated).

Jun 23 '11 at 04:07 PM aldonaletto

PC, nvidia. I've been using a rigidbody controller for ~6months and yesterday was the first time I've stumbled across the error. The specific case was collision with rigidbody blocks that have had a small force applied upwards to make them jump, and when my character hits the top or bottom (depending if the block is falling/rising) there is a small ~1/100-1/200 chance of the error happening.

Jun 24 '11 at 02:22 AM tertle

My PC hasn't NVidia, thus it processes physics entirely by software. This may explain why this error had not occurred to me. On the other hand, you experienced this error under very specific circunstances. Obviously, the best solution would be to check against zero contacts - but you surelly want to know exactly what is happening. I think a good starting point is to test your software in other machines.

Jun 24 '11 at 02:50 AM aldonaletto
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Contact and collision are different slightly i think the mesh many be smaller than the collider (which is not a mesh)

i think contact only occur if the mesh gets toched but i am not sure!

more ▼

answered Jun 23 '11 at 02:42 PM

voxsar gravatar image

voxsar
16 1 1 1

Cool story, bro.

Jun 24 '11 at 02:53 AM Dreamblur

Why was this down-voted?

Jun 24 '11 at 03:01 AM AVividLight

So... umm... this answer was based purely on a guess, contradicts a basic and documented knowledge which was specifically mentioned in the original post, and is just plain wrong, yet someone upvoted it. It must be Opposite Day somewhere in the world. 0_0

Jun 24 '11 at 04:16 AM Dreamblur
(comments are locked)
10|3000 characters needed characters left

Use This:

void OnCollisionEnter(Collision collision) 
{
  ContactPoint contact = collision.contacts[0];
  _NormalContact=contact.normal;

}
more ▼

answered Jun 23 '11 at 03:13 PM

Milad gravatar image

Milad
245 36 42 60

(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:

x2483
x1940
x18

asked: Jun 23 '11 at 02:37 PM

Seen: 882 times

Last Updated: Jun 24 '11 at 04:16 AM