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 _+= 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…