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
0
Question by thieum · Oct 22, 2013 at 10:08 AM · sine-wavemathf.sin

mesh deformation: howto get a coherent move into x and y?

Hello, My question concerns a direction vector that I want to alter along its X and Y only.

I'm working on a mesh deformation script (c#) based on physics collision. I get useful inputs from the colliding objects, such as relative orientation, relative speed, and collision.relativeVelocity in order to obtain a final Vector3 "moveDir" used to move the vertices along.

It looks like this :

         float dist = 1.0f-Mathf.Clamp01(vertToCol.sqrMagnitude/sqrDemRange);
         if( vertToCol.sqrMagnitude < sqrDemRange ) {
             Vector3 moveDir = Vector3.Slerp(vertToMe, flatVertToCenterDir, impactDirManipulator).normalized * moveDelta;
             verts[i] += Quaternion.Inverse(transform.rotation)*moveDir;
         }

You may have recognized variables names coming from "carDamage2.cs" ;°) All the variables aren't listed there, the script is rather long, so don't take the script as it is presented above.

float dist is easy to understand, goes from 0 to 1. Vector3 moveDir is a mix of the colliding object direction and the direction of collision.point toward my collider center. impactDirManipulator offers to tune the latter ratio, currently 0.5f.

All this working well and fast, but I'd like to add variation along Y and X moveDir axis to mimic the way a piece of metal shrinks. It is currently only pushing the verts along Z, simply squeezing the mesh. I'd like the moveDir to behave like a ripple wave and eventually to fade it over distance.

I guess that a sin wave could make the job: not physically accurate, but artistically ok. I've searched in the forum for examples using Mathf.Sin, but they always use time reference to apply a sin wave. My scripts rather uses distance and returns the deformation instantly. I assume that my understanding of Sin or Cos is really bad... so thanks to anyone who can help me on this.

One may have a better approach by calculating the actual Z length between two vertices as to get the X & Y expected move... I fear to run into too heavy calculations.

Thanks for your attention...

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 thieum · Oct 23, 2013 at 08:59 AM 0
Share

As an alternative, I'm also looking at $$anonymous$$athf.PerlinNoise, to get some randomn alteration...

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by whydoidoit · Oct 23, 2013 at 09:04 AM

Well "time" is a just a concept - replace time with distance and you will get the same result. Consider a graph of a Sine wave, time is measured along the bottom - so the graph is just replacing time with distance itself!

Just bear in mind that a value of 1 is going to be a complete Sin cycle, so depending on how far away from the impact point something is you will need to divide that distance to get a value between 0 and 1 for every wave. You may wish to vary that period or just vary the magnitude of the wave as distance from impact increases.

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 thieum · Oct 24, 2013 at 07:57 AM 0
Share

Thank you for your explanation. I also had this in $$anonymous$$d, even if I can't solve it yet. I tried something like this:

 testFloat = moveDir.z*$$anonymous$$athf.Sin (dist/10.0f);
 Vector3 wave$$anonymous$$ove = Vector3.Slerp (moveDir, new Vector3(moveDir.x, testFloat, moveDir.z), dist);

Where the sin is fading with the final lerp based on distance. But my Sin (here applied to Y direction) always returns only one wave...

I've never been interessed in maths, until I stepped in Unity and scripting... I should probably go back to school ;°)

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

15 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

Related Questions

Creating a bouncing game without physics - Question on Mathf.Sin() 0 Answers

Jump character using Sine Curve 1 Answer

How to move prefabs array in sine wave? 2 Answers

Mathf.Sin used to move object left and right but when value changed in game it teleports around 1 Answer

Game lags if there are many objects with this script, how to fix? 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