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 GutoThomas · Mar 14, 2012 at 12:34 AM · timedeformreal

Real-Time Mesh Deforming problem

Hey everyone. I want to know if it's possible to make such a Real-time mesh Deformation System like I am thinking to do. My way to do this would be a OnCollisionEnter in the Mesh to get the Contact Point with the collisor and pass this Vector3 to a function wich is a for loop that check de Distance of each vertice to the contact Point and if it's less than like 20.0F the vertice go down in the y axis with the strength of CollisorMass/DistanceToContactPoint. I apply this way of think in a script but the deformation is not occurring in the Contact Point and sometimes the mesh not even deform. Here are the two necessary voids:

 void Deform(Vector3 colPos, float colMass) {
     
     Vector3 newColPos = new Vector3(colPos.x, 0, colPos.z);
      Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
         Vector3[] vertices = mesh.vertices;
     for(int i = 0; i < mesh.vertexCount; i++) {
         float distance = Vector3.Distance(vertices[i], newColPos);

     if(distance < 20.0F) {
             
             vertices[i] = new Vector3(vertices[i].x, vertices[i].y, vertices[i].z - (colMass/distance));
             
         
     
         }
     }

 mesh.vertices = vertices;
 mesh.RecalculateBounds();
 
 }
 
 void OnCollisionEnter(Collision collider) {
     
     Vector3 colPosition = collider.contacts[0].point;
     Deform(colPosition, collider.gameObject.GetComponent<Rigidbody>().mass);
 }


Hope you guys can help me with this!

Comment
Add comment · Show 1
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 GutoThomas · Mar 14, 2012 at 04:16 PM 0
Share

Someone? :(

1 Reply

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

Answer by Poindexter · Mar 14, 2012 at 09:30 PM

You must convert the contact point to object space, since the mesh.vertices is in object space.

Just substitute the following line in OnCollisionEnter: Vector3 colPosition = renderer.worldToLocalMatrix * collider.contacts[0].point;

Now, for this to work as intended, avoid changing the gameObject's scale. Otherwise you'll have to change how you measure distance in object space.

Comment
Add comment · Show 3 · 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 GutoThomas · Mar 14, 2012 at 09:59 PM 0
Share

Thanks for the reply! Now it works a lot better but the deform still not occurs right where the object hit the mesh. As you can see in the SS, it occurs in a certain distance from the sphere. This distance is constant. Any idea about what is causing this?

SS: http://img850.imageshack.us/img850/5054/deform.jpg

avatar image Bunny83 · Mar 14, 2012 at 10:32 PM 0
Share

The renderer matrices are special matrices for shader parameters. In your usual gamelogic you should better use `transform.worldToLocal$$anonymous$$atrix` or what would be actually easier to read:

transform.InverseTransformPoint(collisionInfo.contacts[0].point)

avatar image GutoThomas · Mar 15, 2012 at 07:07 AM 0
Share

Bunny83, that works perfectly! Thank you ( again ) ! =D Thanks Poindexter, you was on the right way. (:

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

7 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

Weird gameplay slow down problem 1 Answer

Increase health smoothly not instantly? 2 Answers

Building Game w/ Scriptable Objects 1 Answer

Different programming in Flash? 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