Description描述
Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).
返回一個(gè)旋轉(zhuǎn)角度,繞z軸旋轉(zhuǎn)z度,繞x軸旋轉(zhuǎn)x度圆凰,繞y軸旋轉(zhuǎn)y度(像這樣的順序)。
public Quaternion rotation = Quaternion.Euler(0, 30, 0);
繞Y軸旋轉(zhuǎn)30°闰蛔;
transform.rotation=Quaternion.RotateTowards(transform.rotation,)
4種讓一個(gè)物體 移動到另一個(gè)物體的方法
direction = (cubeTra.position - shpereTra.position).normalized
單位向量化;
//第一種 +=
// if (Vector3.Distance (shpereTra.position, cubeTra.position) > 0.1f) {
// shpereTra.position += direction * speed * Time.deltaTime;
// } else {
// shpereTra.position = cubeTra.position;
// }
//第二種 transform.translate
// if (Vector3.Distance (shpereTra.position, cubeTra.position) > 0.4f) {
// shpereTra.Translate (Vector3.right * Time.deltaTime, Space.Self);
// } else { 朝向位置 自身坐標(biāo) 世界坐標(biāo)為 .world
// shpereTra.position = cubeTra.position;
// }
//第三種 每次走一半 物件接近目標(biāo)
// if (Vector3.Distance (cubeTra.position, shpereTra.position) > 0.1f) {
// shpereTra.position = Vector3.Lerp (shpereTra.position, cubeTra.position, Time.deltaTime);
// } else {
// shpereTra.position =cubeTra.position;
// }
Lerp
//第四種 超某個(gè)方向移動 這個(gè)1指的是最大每幀走一米;
// shpereTra.position= Vector3.MoveTowards(shpereTra.position,cubeTra.position,0.01f);
//繞著3個(gè)點(diǎn)移動
public List<Transform> pointList;
int currentIndex=0;
float timer=0;
void Update () {
GoRound ();
}
void GoRound(){
if (Vector3.Distance (transform.position, pointList [currentIndex].position) > 0.1f) { //每幀走1/fps的長度
transform.position =Vector3.MoveTowards( transform.position, pointList [currentIndex].position,1.0f);
} else {
timer += Time.deltaTime;
if (timer >= 2) {
currentIndex=++currentIndex%pointList.Count;
timer = 0;
}
}