Quaternion可以为transform.rotation 赋值
正x轴面向原点,顺时针旋转,z正轴往下,rotation的x正增加。
旋转属性和四元数的欧拉角数值几乎相同
四元数的xyzw数值区间在-1到1之间(为查证开闭区间)
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class RotationStudy : MonoBehaviour
- {
- public Quaternion quaternion;
- public Vector3 quaternion_eulerAngles;
- Ray ray;
- private void Start()
- {
- }
- private void Update()
- {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if(Physics.Raycast(ray,out hit))
- {
- quaternion = Quaternion.LookRotation(hit.point - transform.position);
- quaternion.eulerAngles = new Vector3(0, quaternion.eulerAngles.y,0);
- quaternion_eulerAngles = quaternion.eulerAngles;
-
- transform.rotation = quaternion;
- //transform.rotation = new Quaternion();
- }
- }
-
- }