Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The stiffness of the spring
- // A bigger value makes the bounce animation faster and a short value makes it slower"
- float k = 100;
- // The compression of the spring
- float x = 0.5;
- // The velocity of the spring each frame
- float v = 0;
- void Update () {
- float F = -k * this.compression; // F = kx
- this.v += F * Time.deltaTime; // v = at
- this.x += this.v * Time.deltaTime; // x = vt
- this.transform.localScale = new Vector3(1 + this.x, 1 - this.x, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement