• 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 alexm5 · May 11, 2013 at 09:53 AM · collidertriangle

How to add a MeshCollider to this object(triangle) that I made?

void Start() {

     gameObject.AddComponent("MeshFilter");
     gameObject.AddComponent("MeshRenderer");
 gameObject.AddComponent();
 gameObject.rigidbody.useGravity= false;
     Mesh mesh = GetComponent<MeshFilter>().mesh;
     mesh.Clear();
     mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0.25f, 0, 0.75f), new Vector3(0.75f, 0, 0.25f)};
     mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0.25f, 0.75f), new Vector2(0.75f, 0.25f)};
     mesh.triangles = new int[] {0, 1, 2};
     
 
 }


I want to add collider to it, for instance if an object is falling from the sky, along it's Y axis, and it hits this new object to stop on it. Of course now it just passes through it. I understand i have to use MeshCollider, but I haven't used it before, thus I really don't know how? Thank you for your help.

Comment
Add comment · Show 3
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 Fattie · May 11, 2013 at 10:58 AM 0
Share

huh? just add a simple primitive collider .. almost always just a sphere.

it is almost inconceivable you would need to use "mesh colliders" for something so very simple.

generally "mesh colliders" are never used in video games, only in veery unusual circumstances.

add a sphere collider. if you want to be REALLY fancy, add a cube collider - but why?

avatar image Eric5h5 · May 11, 2013 at 05:13 PM 0
Share

$$anonymous$$esh colliders are common in video games, but only for static scenery, not moving objects.

avatar image Fattie · May 12, 2013 at 07:49 AM 0
Share

They're not common dude. If you survey the market, 99.999% of all video games being played at any instant are now Angry Birds. No mesh ;-)

If we'd asked this question in 1995 it would have been "Solitaire" -- again, no mesh :)

2 Replies

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

Answer by whebert · May 11, 2013 at 04:59 PM

I agree with @Fattie, other colliders will probably do the job just as well and are much faster. If you wanted the flat sides of a collider, then a BoxCollider would do. You could add the following to the end of the Start() script above:

 gameObject.AddComponent<BoxCollider>();

And the BoxCollider should size itself to encompass your triangle. If you really want a MeshCollider, your mesh will need to be more than just a triangle I believe since it is infinitely thin and your RigidBody will attempt to compute the inertial tensor based on the matching infinitely thin MeshCollider and fail - so you'll get an error in that case.

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 whebert · May 11, 2013 at 05:10 PM 0
Share

Oh yeah, forgot to mention, you'll need to remove your line gameObject.AddComponent(); since you aren't specifying any type and should get a compile error of course...

avatar image
0

Answer by JscriptFless · May 11, 2013 at 11:53 AM

Component> Physics> Mesh collider.

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 alexm5 · May 11, 2013 at 03:35 PM 0
Share

ok I do that, but I need to set up a collider just for this triangle not for standard (cube,sphere,capsule, etc..)? How do I save the mesh as a triangle, I think is my problem?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

What's a rough start or outline to creating my own physics? 0 Answers

Glitchy Convex Mesh Collider 1 Answer

Internal collisions 1 Answer

What's a rough start or outline to creating my own physics? 0 Answers

Hitting Collider,Not Being Effected ? 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