daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // The stiffness of the spring
  2. // A bigger value makes the bounce animation faster and a short value makes it slower"
  3. float k = 100;
  4.    
  5. // The compression of the spring
  6. float x = 0.5;
  7.  
  8. // The velocity of the spring each frame
  9. float v = 0;
  10.  
  11. void Update () {
  12.     float F = -k * this.compression; // F = kx
  13.     this.v += F * Time.deltaTime; // v = at
  14.     this.x += this.v * Time.deltaTime; // x = vt
  15.  
  16.     this.transform.localScale = new Vector3(1 + this.x, 1 - this.x, 1);
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top