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 sam.ibbitson · Dec 14, 2011 at 11:41 PM · c#meshproceduralmeshcollider

Mesh collider on procedurally generated mesh

Hi,

I'm having a problem assigning my mesh a collider.

I've tweaked the CrumpleMesh scene (from the procedural examples package) and now have a flat plane that, on run time, is deformed by Perlin noise. I can assign the mesh itself a collider but this does not follow the contours of the deformed mesh (e.g. the hills and troughs).

So- in light of the above, what would be the best way of assigning a collider to my mesh after it has been deformed (I imagine I need to add something to the script, but can't quite work out what).

FYI, I'm using the C# version of the script:

 using UnityEngine;
 using System.Collections;
 using Graphics.Tools.Noise;
 using Graphics.Tools.Noise.Primitive;
 using Graphics.Tools.Noise.Filter;
 
 public class CrumpleMesh : MonoBehaviour {
     
     public float scale = 1f;
     public float speed = 0f;
     public bool recalculateNormals = false;
     
     private Vector3[] _baseVertices;
     private IModule3D _noise;
     
     //seed
     private Mesh _mesh;
     static private System.Random _rnd = new System.Random(999);
     
     /// <summary>
     /// 
     /// </summary>
     void Start () {
         _mesh = GetComponent<MeshFilter>().mesh;
     }//end Start
     
     /// <summary>
     /// 
     /// </summary>
     void Update () {
         
         if (_noise == null){
             CreatePrimitive();
         }//end if
         
         if (_baseVertices == null){
             _baseVertices = _mesh.vertices;
         }//end if
         
         Vector3[] vertices = new Vector3[_baseVertices.Length];
         
         float timex = Time.time * speed + 1.2584f;
         float timey = Time.time * speed + 40.6584f;
         float timez = Time.time * speed + 1.6518f;
         
         for (int i = 0; i < vertices.Length; i++){
             
             Vector3 vertex = _baseVertices[i];
                     
             vertex.x += _noise.GetValue(timex + vertex.x, timex + vertex.y, timex + vertex.z) * scale;
             vertex.y += _noise.GetValue(timey + vertex.x, timey + vertex.y, timey + vertex.z) * scale;
             vertex.z += _noise.GetValue(timez + vertex.x, timez + vertex.y, timez + vertex.z) * scale;
             
             vertices[i] = vertex;
             
         }//end for
         
         _mesh.vertices = vertices;
         
         if(recalculateNormals){
             _mesh.RecalculateNormals();
         }//end if
         
         _mesh.RecalculateBounds();
         
     }//end Update
     
     /// <summary>
     /// 
     /// </summary>
     private void CreatePrimitive(){
         
         SimplexPerlin primitive = new SimplexPerlin();
         primitive.Seed = (int)(_rnd.Next() * _rnd.Next());
         
         SinFractal filter = new SinFractal();
         filter.OctaveCount = 10f;
         filter.Primitive3D = primitive;
         
         _noise = primitive;
         
     }//end CreatePrimitive
     
 }//end class

Thank you for any responses.

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
3
Best Answer

Answer by Eric5h5 · Dec 15, 2011 at 12:13 AM

Copy the generated mesh to the meshcollider's mesh. i.e., GetComponent<MeshCollider>().mesh = _mesh;. Keep in mind that updating a mesh collider is very slow, and not actually something you want to do in Update.

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 sam.ibbitson · Dec 18, 2011 at 10:31 AM 0
Share

This is what I was looking for- thanks!

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

6 People are following this question.

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

Related Questions

Trouble with Inaccurate Mesh Collider 0 Answers

How to make mesh having array of vertices? 1 Answer

Convex Mesh Collider on Procedurally generated mesh does not conform.. 2 Answers

Distribute terrain in zones 3 Answers

Trouble Creating a Procedural Mesh on a Rotated Game Object 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