Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement