x


Why does OnCollisionStay returns multiple contact points in such a strange way?

Hi there, updated this Question, because of something I noticed and to clarify some more:

I've got a rigidbody with a spherecollider and need a way to keep track of all the points it is currently in contact with. I thought OnCollisionStay would be the way to do this, but somehow it gives unexpected results.

My test cases are the following: The SphereCollider is sitting on a stairway, in case A composed of BoxColliders, in case B a single mesh collider/imported 3dmodel

CASE A

CASE B

Than I'm printing the contact.points with this script:

 function OnCollisionStay (collision : Collision) {
        grounded=true;
        print(collision.contacts.Length);
        for (var contact : ContactPoint in collision.contacts) {
            print(contact.otherCollider + " " + contact.point);
        }
        collisions = collision;

    }

As you already may have noticed in the pictures the console output is very, very strange:

In Case A it says it has 2 contact.points, but then prints 2 times the coordinates of the first contact and than 2 times the coordinates of the second, instead of printing both coordinates at once.

CASE B is even worse it says it has 2 to 8 contacts and about half of the printed coordinates belongs to the first and half to the second contact point.

I considered that this might have to do with the number of vertices of the stairway mesh compared to the two box colliders, but I dont see why this should be the way oncollisionstay is supposed to work. Maybe I'm wrong but shouldn't be the output more like this:

Number of Contacts

Coordinate 1.Contact

Coordinate 2.Contact

...

Number of Contacts

Coordinate 1.Contact

Coordinate 2.Contact

...

If anybody knows the reason for this, or has any suggestions for a work arround, so that I can have an output like shown above, I would be very glad.

I hope I described the problem well enough, otherwise feel free to ask and I will clarify. As alway any help is appreciated. Thanks!

more ▼

asked Mar 11 '11 at 08:53 PM

Christian 7 gravatar image

Christian 7
11 1 1 4

Could you also print out the normal of the contact?

Mar 12 '11 at 05:51 PM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x2497
x1698
x292
x125

asked: Mar 11 '11 at 08:53 PM

Seen: 1025 times

Last Updated: Mar 12 '11 at 02:46 PM