一.Transform:
-
eulerAngles:欧拉角
- x,y和z角度分别表示围绕z轴旋转z度,围绕x轴旋转x度和围绕y轴旋转y度。
- 不要增加它们,因为当角度超过360度时,它将失败。请改用Transform.Rotate。
- 实践后没有实现
-
LookAt:看向某一方向
-
public void Rotate(Vector3 eulers, Space relativeTo = Space.Self):
- 放在Update下面,持续旋转
- 度数旋转
- 欧拉旋转
- public void RotateAround(Vector3 point, Vector3 axis,float angle):
-
rotation:存储一个四元数。您可以使用它来旋转GameObject或提供当前旋转。请勿尝试编辑/修改旋转。Transform.rotation小于180度。
- public static Quaternion LookRotation(Vector3 forward, Vector3 upwards = Vector3.up):
- Z轴对齐forward,X轴对齐,forward和upwards的叉积
public Transform target;
void Update()
{
Vector3 relativePos = target.position - transform.position;
// the second argument, upwards, defaults to Vector3.up
Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
transform.rotation = rotation;
}
- Quaternion.Euler
void Start()
{
// A rotation 30 degrees around the y-axis
Quaternion rotation = Quaternion.Euler(0, 30, 0);
}
- public static Quaternion Slerp(Quaternion a, Quaternion b, float t);
- 在a和b之间进行球面插值。限制参数t在[0,1]范围内。
public class ExampleClass : MonoBehaviour
{
public Transform from;
public Transform to;
private float timeCount = 0.0f;
void Update()
{
transform.rotation = Quaternion.Slerp(from.rotation, to.rotation, timeCount);
timeCount = timeCount + Time.deltaTime;
}
}
- public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);
- 创建从旋转fromDirection到的旋转toDirection。
- 通常,您可以使用它来旋转变换轴.
void Start()
{
// Sets the rotation so that the transform's y-axis goes along the z-axis
transform.rotation = Quaternion.FromToRotation(Vector3.up, transform.forward);
}
- Quaternion.identity
- Quaternion.RotateTowards
- from四元数旋转朝向to通过的角步骤maxDegreesDelta
- public static Quaternion AngleAxis(float angle, Vector3 axis);
- Quaternion.Angle
public class ExampleClass : MonoBehaviour
{
public Transform target;
void Update()
{
float angle = Quaternion.Angle(transform.rotation, target.rotation);
}
}