- Home /
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?
Answer by Bunny83 · Jul 09, 2012 at 11:17 AM
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.
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?
Ok, this is of course something different. $$anonymous$$eep in $$anonymous$$d that the normal is the surface normal at the collision point. What collider do you use?
One object is using mesh collider and the other object is using sphere collider.
Your answer
Follow this Question
Related Questions
How do I reset part of a scene? 1 Answer
Addressable for Oculus Go 2 Answers
Scripted Position Handle Not Locking Axis 0 Answers
Camera not showing in scene view 0 Answers