Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by highpockets · Jul 22, 2013 at 07:18 AM · if-statementsnormalscontactcontact.pointcontacts

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image moha · Jul 22, 2013 at 07:25 AM 0
Share

the result is ( 1.0, 0.0, 0.0 ), for every contact point ? you don't have one which is different ?

avatar image highpockets · Jul 22, 2013 at 07:29 AM 0
Share

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.

avatar image hatuf · Jul 22, 2013 at 07:54 AM 0
Share

Can you try to print cPoint.normal.y ins$$anonymous$$d of the whole vector? Unity rounds it for displaying it neatly.

avatar image highpockets · Jul 22, 2013 at 08:08 AM 0
Share

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 ).

avatar image highpockets · Jul 22, 2013 at 08:12 AM 0
Share

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..

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hatuf · Jul 22, 2013 at 08:29 AM 0
Share

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"){ ...

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reading normal force between colliders 3 Answers

Using Contact Point normals to allow for player jumping through platforms? 2 Answers

Normal of collision hit is moving downwards 0 Answers

Collision with no contact? 2 Answers

Force Of Jump Determined By Collision.Contacts 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges