Skip to content

Instantly share code, notes, and snippets.

@andyzinsser
Created February 10, 2014 23:43
Show Gist options
  • Save andyzinsser/8926544 to your computer and use it in GitHub Desktop.
Save andyzinsser/8926544 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class SpinningReel : MonoBehaviour {
private bool isSpinning = true;
public float smooth = 10f;
void Update () {
if (Input.GetKeyUp (KeyCode.S))
{
Debug.Log("S pressed");
Quaternion newPosition = transform.rotation * Quaternion.Euler(45f, 0f, 0f);
transform.rotation = Quaternion.Slerp(transform.rotation, newPosition, Time.deltaTime * 100f);
}
}
}
@VelociCopter
Copy link

using UnityEngine;
using System.Collections;

public class SpinningReel : MonoBehaviour {

private Vector3 targetRotation = transform.rotation;
private float interpolant = 0f;

void Update () {
    //
    // Detect a new target conditionally based on key-press
    //
    if (Input.GetKeyUp (KeyCode.S)) {
        Debug.Log("S pressed");
        // The new target is 45 deg above the last target
        targetRotation = targetRotation * Quaternion.Euler(45f, 0f, 0f);
        this.interpolant = 0f;
    }

    //
    // Update the interpolating rotation
    //
    if( transform.rotation != this.targetRotation ) {
        this.interpolant += Time.delaTime;
        transform.rotation = Quaternion.Slerp( transform.rotation, newPosition, this.interpolant );
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment