Skip to content

Instantly share code, notes, and snippets.

@igolden
Created October 18, 2017 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igolden/1f38552ae2f4f4f81c6a77e4d8a3f2b3 to your computer and use it in GitHub Desktop.
Save igolden/1f38552ae2f4f4f81c6a77e4d8a3f2b3 to your computer and use it in GitHub Desktop.
Rotate object in Unity 3d
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
void Update() {
float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment