参考教程
http://coder.beitown.com/archives/1279
1.移动的几种方式:
transform.Translate(Vector3); //移动到目标点,可使用 Time.delta * Vector3.normalized 逐贞 匀速 移动过去,
transform.position = Vector3;
2.旋转的几种方式
transform.rotation = Qua;
transform.Rotate();
var rt = Vector3.RotateTowards(transform.forward, target.transform.position, Time.deltaTime, 0);
transform.rotation = Quaternion.LookRotation(rt);
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, Time.deltaTime * speed);
Vector3常用API.
1.Vector3.ClampMagnitude(Vector3 vector,float maxLength)锁定最大坐标。
用途:限制某个物体的可移动范围, 比如 老夫子大招捆人,只能在半径范围内移动。
官方示例:
1 | using UnityEngine; |
var v100 = new Vector2(1, 1);
var v101 = new Vector2(2, 0);
var dotValue = Vector2.Dot(v100, v101);
var angle = Vector2.Angle(v100, v101);
var dotValue2 = v100.magnitude * v101.magnitude * Mathf.Cos(angle * Mathf.Deg2Rad);
var cosValue = dotValue / (v100.magnitude * v101.magnitude);
var angleByCosValue = Mathf.Acos(cosValue) * Mathf.Rad2Deg;
Debug.Log(" angle by cos value : " + angleByCosValue);
Debug.Log(" v1 v2 之间的cos 值 :" + cosValue + " " + Mathf.Cos(angle * Mathf.Deg2Rad));
Debug.Log(">>>>>>>>> Vector.Dot : " + dotValue + " angle : " + angle + " dotValue2: " + dotValue2);