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
1
Question by PatrickStas · Oct 13, 2012 at 07:49 PM · collidermeshmeshcollidershapegenerated

MeshCollider has different shape than MeshFilter

Hello,

I am generating mesh and then I am assigning it to MeshCollider's sharedMesh. My problem is showed right on the attached picture. The shape of purple object is exactly what I wanted. However mesh collider has a different shape, and I expected it to have the same shape as object has.

This is the code of generating:

 public class MeshGeneratortTest : MonoBehaviour {
     public int width = 10;
     
     void Start() {
           gameObject.AddComponent<MeshFilter>();
           gameObject.AddComponent<MeshRenderer>();
           gameObject.AddComponent<Rigidbody>();
           Mesh mesh = GetComponent<MeshFilter>().mesh;
           mesh.Clear();
           mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 0, width), new Vector3(20, 2, 0), new Vector3(20, 2, width), 
                                              new Vector3(34, 11, 0), new Vector3(34, 11, width) };
           mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)};
           mesh.triangles = new int[] {0,1,2,   1,2,3,   2,3,4,   3,4,5, };
           mesh.RecalculateNormals();
           gameObject.AddComponent<MeshCollider>();
           GetComponent<MeshCollider>().sharedMesh = mesh;
           GetComponent<MeshCollider>().convex=true;
         
     }
 }    

I know I am not editing tangents of vertices, but from what I read i understood that's used mainly just for some lighting systems and shaders, Am I right ? Could someone tell me what I messed up or just push me to right direction ?

// Edit: I noticed that when I pause the game and take a look at collider mesh in inspector view, it looks right. However in real, in scene view, there are 2 extra triangles on collider connecting both side of object. Are there some specials rules for meshes ? So maybe unity is trying to fix something I did wrong when I initialised vertices and triangles ? alt text

Thank you very much.

differentviews.png (25.1 kB)
weird.jpg (39.5 kB)
Comment
Add comment
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

1 Reply

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

Answer by Eric5h5 · Oct 13, 2012 at 11:47 PM

You're making it a convex mesh, hence what you're getting is expected behavior.

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 PatrickStas · Oct 14, 2012 at 12:07 AM 0
Share

Oh boy, I feel stupid I did not realized right away. Thank you.

avatar image Fattie · Oct 14, 2012 at 05:16 AM 0
Share

legendary answer ...

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

Colliders on this spider 1 Answer

How to correct add collider to every child of gameobject? 1 Answer

Making two mesh colliders collide 2 Answers

Setting Mesh Colliders convex through script 1 Answer

Mesh collider component doesn't have mesh. 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