四元数
MotionScript
using UnityEngine; using System.Collections; public class MotionScript : MonoBehaviour { public float speed = 3f; void Update () { transform.Translate(-Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0); } }
LookAtScript
using UnityEngine; using System.Collections; public class LookAtScript : MonoBehaviour { public Transform target; void Update () { Vector3 relativePos = target.position - transform.position; transform.rotation = Quaternion.LookRotation(relativePos); } }
GravityScript
using UnityEngine; using System.Collections; public class GravityScript : MonoBehaviour { public Transform target; void Update () { Vector3 relativePos = (target.position + new Vector3(0, 1.5f, 0)) - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); Quaternion current = transform.localRotation; transform.localRotation = Quaternion.Slerp(current, rotation, Time.deltaTime); transform.Translate(0, 0, 3 * Time.deltaTime); } }
SomeClass
using UnityEngine; using System.Collections; public class SomeClass : MonoBehaviour { void Start () { transform.rotation = Quaternion.identity; } }