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).
返回一个旋转角度,绕z轴旋转z度,绕x轴旋转x度,绕y轴旋转y度(像这样的顺序)。
public Quaternion rotation = Quaternion.Euler(0, 30, 0);
绕Y轴旋转30°;
transform.rotation=Quaternion.RotateTowards(transform.rotation,)
4种让一个物体 移动到另一个物体的方法
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 { 朝向位置 自身坐标 世界坐标为 .world
// shpereTra.position = cubeTra.position;
// }
//第三种 每次走一半 物件接近目标
// 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
QQ图片20170918201048.png
//第四种 超某个方向移动 这个1指的是最大每帧走一米;
// shpereTra.position= Vector3.MoveTowards(shpereTra.position,cubeTra.position,0.01f);
//绕着3个点移动
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;
}
}
网友评论