x


Same scene and object in different levels not giving similar collision values

We created a scene and object for two different levels of our game. Created script for detecting collision. In one case Collision.contact[0].normal.y is giving proper values for the game. But the same script on another level giving a value like 0.9999998 which seems to be a single value which is not expected. Any clue on this?

more ▼

asked Jul 09 '12 at 10:03 AM

manojpj gravatar image

manojpj
15 2 10 13

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

1 answer: sort voted first

All those values are floating point values. A Vector3 is made up of 3 float values. 0.9999998 can be considered as 1.0. This is a general precision problem.

You never should direct compare floating point values, they would almost never match.

So if you want to check if the normal is pointing upwards, just test for a range like this:

if (Collision.contact[0].normal.y > 0.99f)

It would help to know what you actually want to do. You just described a common, well known phenomenon, so we can't say much more about this without more information.

more ▼

answered Jul 09 '12 at 11:17 AM

Bunny83 gravatar image

Bunny83
45.4k 11 49 207

Thanks for your quick response.

if (collision.contacts[0].normal.y > 0.7071f){ deleteObject(); }

The code is meant for checking an object collides with another object with less than 45 degrees of inclination. The same code works with other scenes. But it is not working with one particular scene. In all the cases the value getting from collision.contacts[0].normal.y is 0.99998 even though they are colliding at different angles. Anything I can do about this?

Jul 09 '12 at 11:58 AM manojpj

Ok, this is of course something different. Keep in mind that the normal is the surface normal at the collision point. What collider do you use?

Jul 09 '12 at 01:52 PM Bunny83

One object is using mesh collider and the other object is using sphere collider.

Jul 11 '12 at 06:25 AM manojpj
(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:

x718
x126
x12

asked: Jul 09 '12 at 10:03 AM

Seen: 310 times

Last Updated: Jul 11 '12 at 06:25 AM