Created
October 18, 2017 05:45
-
-
Save igolden/1f38552ae2f4f4f81c6a77e4d8a3f2b3 to your computer and use it in GitHub Desktop.
Rotate object in Unity 3d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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