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 rorypickering · Mar 26, 2013 at 11:03 AM · meshmeshcolliderphysxmeshcombine

Merging meshes at runtime - upside down normals?

Hello,

I am creating a side scrolling game that will "randomly" generate the terrain as it goes, and then the user will kick a ball and it will bounce along until it comes to a stop. I put randomly in quotation marks as it isn't completely random, it chooses from a select group of meshes which to copy and place at the end.

example mesh

Each of my meshes ends on a slight flat section, to allow smooth joining. When I align the planes together, sometimes when the ball lands at the join it created unexpected results, like the ball bouncing backwards. (i tried this using meshes of 3d objects, and changed to a flat plane as i thought it may fix it, but it doesn't but it cut the verts down to around 10% so i kept them!)

Mesh Merging

Next I merged the meshes on the fly (the 5 closest MeshFilters to the ball are combined and set to a MeshCollider of a seperate game object) this all works fine but again I was still getting the unexpected results. SOOOOOO... I then tried to strip out the overlapping vertices from the mesh after the combine, and then ran Mesh.RecalculateBounds to update it.

 List<Vector3> newPoints = new List<Vector3>();
         
     for( int i = 0; i < meshVerticeCount; i++)
     {
         Vector3 point =  meshToSort.vertices[i];
         bool AddPoint = true;
         for( int j = 0; j < newPoints.Count; j++)
         {
             if( point == newPoints[j])
             {
                 AddPoint = false;
             }
         }
         if(AddPoint) newPoints.Add(point);
     }
 
     Vector3[] verticeArray = new Vector3[ newPoints.Count ];
     
     for( int k = 0; k < newPoints.Count; k++)
     {
         verticeArray[k] = newPoints[k];
     }
     
     meshToSort.Clear();
     meshToSort.vertices = verticeArray;
     
     meshToSort.RecalculateNormals();
     meshToSort.RecalculateBounds();



When I Debug.Log the count before and after the this method is called, It is removing the correct number of vertices, (2 overlaping per plane, exept the last) and the mesh all appears fine, but im still getting these odd bounces.

Just to throw another spanner in the works, I noticed that now it doesnt just happen where the meshes join, but anywhere!! If I bounce a ball at a plane, 9/10 it'll act as expected but 10% of the time it'll bounce backwards.

Is it possible that the normals of one or more of the triangles could be upside down to cause this? is my method of removing over lapping vetrices too easy to be true, should i be linking up the trianlges to the missing points or is all of that calculated automatically?

Any help on this would be greatly appreciated as this has been 2 days of hair pulling development and it's driving me mad!

Cheers in advance!

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 whydoidoit · Mar 26, 2013 at 11:21 AM 0
Share

Well recalculating the normals will use the winding order (which shouldn't have changed) and then work out the normal based on the differences between the planes on the two sides - you can check if this is working a you expect by shining a light on it and turning it around - I expect it will be fine. I'm wondering if it's the physics and collision detection - how do you have that configured?

avatar image rorypickering · Mar 26, 2013 at 11:45 AM 0
Share

All the physics settings are as unity standards the $$anonymous$$aterials i've used all values are set to 0 except Dynamic frication 0.7 and bounciness 0.65 Thank you for your time!

0 Replies

· Add your reply
  • Sort: 

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

11 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

Related Questions

Mesh colliders with PhysX 2.8. 3 Answers

Turn Off Mesh.Bake Scaled Mesh PhysX CollisionData ? 0 Answers

ok combining meshes could be easy... WHAT THE F*** 0 Answers

Collision mesh data problem in Unity WebPlayer 2 Answers

Pointcast? - Raycast Point X from same Point X 0 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