- Home /
contacts.normal question
Hi there,
I'm trying to check contact point normals when a collisions occur. I basically have an if statement that checks if the contacts.normal.y is not equal to zero. The problem is whether the normal is zero'd out or not, the if statement remains true. Here is my code, which I'm sure is wrong:
foreach( ContactPoint cPoint in collision.contacts )
{
if( cPoint.normal.y != 0f )
{
print ("cPoint normal:" + cPoint.normal );
gameObject.layer = 11;
break;
}
else
{
continue;
}
}
The "print" line reads out ( 1.0, 0.0, 0.0 ), which, to me, looks like the y value is at 0, but the statement is true so I'm super confused. Can anyone help me out with this please?
Thanks
the result is ( 1.0, 0.0, 0.0 ), for every contact point ? you don't have one which is different ?
That is the one that breaks the foreach statement so it only makes it that far, but I have looked at each contact point normal and they are the same.
Can you try to print cPoint.normal.y ins$$anonymous$$d of the whole vector? Unity rounds it for displaying it neatly.
Very strange, it gave me this 5.74425E-06 when printing just the y value and I printed out the whole vector and it showed ( -1.0,0.0,0.0 ).
All I need is the Vector3 value that displays in the console. Is there a way to state my if statement to just do that ? I tried $$anonymous$$athf.Approximately( cPoint.normal.y, 0f ), but that still gave me the same result..
Answer by highpockets · Jul 22, 2013 at 08:25 AM
Ok, I messed around a bit and I came up with a workablish solution. My if statement looks like this:
if( cPoint.normal.y > 0.1f || cPoint.normal.y < -0.1f )
I only need it for approximation anyways, so this works.
Unity automatically turns the output to a string with one decimal point so you can also do this for example:
float yValue = 0.12345f;
if(yValue.ToString("F1") == "0.0"){ ...