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 malkere · Mar 31, 2014 at 01:01 PM · collisionmeshinstancemeshcollider

How to setup collision with freshly generated mesh and prefabs

The setup: There are dots(8) that spawn randomly just in front of a plane on start. The player then draws three dots with mouse-clicks. The dots connect when created, and generate a triangle(mesh) between the three dots when the third is instanced.

The desire: collision detection between the dots and the triangle. in other words, I want to award the player with the dots they've outlined with his/her three clicks and not dots outside of the triangle.

I've been reading through tutorials and answers and tried copying and pasting all sorts of code and can't get anything to trigger with the mesh. The dots will all collide (or trigger for that matter) with the plane if I ask them to, but not the mesh. They are clearly intersecting in the scene.

Is it because of the way I'm using mouse-click points in game-time to generate the mesh? perhaps I am not applying the mesh data to its collider properly? or perhaps the way to mesh just appears all the sudden it's not passing through the proper collision checks? it's going right through the dots? I am not checking isTrigger on the dots when I try collision, though on when trying OnTriggerEnter/Stay() etc. I do have a rigidbody on the dots, they do collide with the wall if I turn it's meshcollider on.

on the triangle/mesh:

     void OnCollisionEnter(Collision dot){
         Debug.Log ("collision on tri");
     }
 
     public void CreateTriangle() {
         Mesh mesh = new Mesh();
         GetComponent<MeshFilter>().mesh = mesh;
                 mesh.Clear();
         mesh.vertices = _vertices;
         mesh.uv = _UV;
         mesh.triangles = _triangles;
         mesh.normals = _vertices;
         _active = true;
         GetComponent<MeshCollider>().sharedMesh = mesh;
         
 //        MeshCollider meshc = gameObject.AddComponent(typeof(MeshCollider)) as MeshCollider;
 //        meshc.sharedMesh = mesh;
 //        mesh.RecalculateNormals();
     }


on the dots:

     void OnCollisionEnter(Collision tri) {
         Debug.Log ("Collision on" + gameObject.name + "with " + tri.ToString());
     }

Thanks for any insight. Very new to this level of programming, but if I can get this one last step to work I can get everything else rolling =D

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 malkere · Mar 31, 2014 at 12:50 PM 0
Share

I understand why primitives would work a lot faster/easier etc. but I can't imagine how to draw primitives based on the triangle input the game is based off... the whole principle is connecting vertexes. eventually the player get to make 4 dots, 5 dots, etc., each checking against the rest to see if it can make any new triangles. If anyone can think of a better way to go about that than I am trying, I'll gladly consider it =D

avatar image malkere · Mar 31, 2014 at 01:32 PM 0
Share

maybe I should raycast from the dots and see if they hit with the triangle?

avatar image malkere · Mar 31, 2014 at 09:53 PM 0
Share

I got a camera projected raycast on click to intersect with the triangle.. so it's collider works... just not with the dots?? must be the way they are instanced on top of one another?

1 Reply

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

Answer by malkere · Apr 03, 2014 at 08:55 AM

well no answers yet. but I did get raycast to collide with the triangle face. solved via bypassing mesh/primitive collision and just using the primitives locations to cast rays at the one-sided, single face mesh.

I assume the standard collision process isn't working because of the way it's just instantiating the mesh right within some of the dots. If I cast a ray from the camera it collides with the triangle face, so I scripted it to fire and test a ray from each of the dots locations and provide feedback which both lets me create a unique and precise set of triangles each run and still know exactly if any of the dots are caught within it or not.

I got hung up for quite a while before I learned Vector3(0,0,-1) for the ray.direction to get the ray firing not just from where I wanted it, but to where I wanted it.

Comment
Add comment · 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

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

22 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Implementing Meshless Deformation 0 Answers

Cant walk through doorway mesh created in Blender 1 Answer

Generated mesh collider on a generated mesh becomes a big box instead of taking mesh's shape 1 Answer

how can I instantiate an object specifically at the intersection of a collider and a mesh 1 Answer

MeshCollider Failure at high velocities 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