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 easilyBaffled · Sep 07, 2012 at 03:04 AM · raycastnormaltriangle

Normal of the edge between two triangles

I have a ball rolling through the tube, and after ever roll I do a raycast down, and then get the normal of that point so I can get the difference between it and the initial raycast and then rotate the ball can be parallel to the ground. The problem is, the tube is made up of a series of triangles, as most things are. If I got the normal of the present triangle it would point strait up, but because of there the ball is the ray is casting down on an edge between two triangles and the normal is pointing at an odd angle. In the picture the green is the raycast, and the red is the normal. Is there a way that I can tell the difference between triangle proper and an edge between two triangles. I've included my code so you might better understand what I am trying to do.

       //Move ball down onto the surface.
     Physics.Raycast(down.position, -down.up, hit);
     transform.position.y -= (hit.distance - transform.GetComponent(SphereCollider).radius*scale);
 
     //Rotate the ball around a point very close to where the ball is touching the tube, it will roll but will be elevated slightly which is why it has to be brought back down in the above code
     Physics.Raycast(child.position, -child.up, hit);
     transform.RotateAround(hit.point, child.right, 5);
     
     //rotate the children to realign 
     child.Rotate(child.right * -5);
     down.Rotate(down.right * -5);
 Debug.DrawRay(down.position, -down.up, Color.green, 5);
     
     //Rotate children so we can find what the normal of the surface is.
     Physics.Raycast(down.position, -down.up, hit);
     //if surface is an edge rotate by a little
     Debug.DrawRay(hit.point, hit.normal, Color.red, 5);
     rot = -Vector3.AngleBetween(down.position, hit.normal);
     child.Rotate(child.right * rot);
     down.Rotate(down.right * rot);



alt text

screen shot 2012-09-06 at 10.53.25 pm.png (166.5 kB)
Comment
Add comment · Show 2
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 easilyBaffled · Sep 07, 2012 at 04:48 PM 0
Share

Ah you would normally be right, but unfortuantly this is a far from normal case, you see the tube(imported from maya) and the ball do not interact properly when left to physics. The ball wont sit on the tube properly, and will tend to freak out after a few seconds. I posed this question to UA all about it a couple of weeks ago, but there has been no answer yet. http://answers.unity3d.com/questions/308191/mesh-collider-maya-import.html

avatar image easilyBaffled · Sep 07, 2012 at 05:37 PM 0
Share

I tried that but heres the think, ins$$anonymous$$d of sitting proper, Y axis pointing strait up, it tilts. I don't get it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Sep 07, 2012 at 04:21 AM

Maybe you want this: http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-barycentricCoordinate.html

Comment
Add comment · Show 2 · 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 easilyBaffled · Sep 11, 2012 at 06:03 PM 0
Share

Now did come across this before, but even despite the example given I have no real idea how to use it, any chance you know how, or have any better examples?

avatar image Eric5h5 · Sep 11, 2012 at 06:08 PM 0
Share

I used it once, but it was kind of a long time ago, so I don't remember any specifics.

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

8 People are following this question.

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

Related Questions

Automatically rotating objects to fit on to others 0 Answers

How do I obtain the surface normal for a point on a collider (can't use RaycastHit.normal)? 3 Answers

How can i get point reletive to hit.point 0 Answers

Angle between Ray and Normal 1 Answer

Why does the raycast hit only objects/faces of a certain rotation? 1 Answer


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