Cube 逐点运动到点停止
来源:互联网 发布:网络巫师剧情介绍 编辑:程序博客网 时间:2024/05/16 17:02
首先生成如图的Cube物体;
Cube物体从原始位置(6.011,2.54,0)开始,运动到(0,0,0)位置后,转向位置(-3, 2, 0),最后转向(4, 4, 0)位置停止运动。
新建一个名为PtoPMove的C#脚步;
using UnityEngine;
using System.Collections;
public class PtoPMove : MonoBehaviour {
public GameObject moveCube;
public Vector3[]pArr;
public int len;
private float speed=3.0f;
private float s; //当前要移动的距离
private float dis;
private int pIndex = 0;
private float speedX;
private float speedY;
private int moveFlag;
// Use this for initialization
void Start () {
pArr = new Vector3[3];
pArr [0] = new Vector3 (0, 0, 0);
pArr [1] = new Vector3 (-3, 2, 0);
pArr [2] = new Vector3 (4, 4, 0);
len = pArr.Length;
moveCount ();
}
void moveCount(){
Vector3 p = pArr [pIndex];
Vector3 v = moveCube.transform.position; //重要:v此时是时刻在变得三维坐标,而不是固定的第一个点的位置;
float dx = p.x - v.x;
float dy = p.y - v.y;
s = Mathf.Sqrt (dx * dx + dy * dy);
float hudu = Mathf.Atan2 (dy, dx);
speedX = speed * Mathf.Cos (hudu);
speedY = speed * Mathf.Sin (hudu);
moveFlag = 1;
dis = 0;
}
// Update is called once per frame
void Update () {
if (moveFlag == 1) {
moveCube.transform.Translate(Vector3.right*Time.deltaTime*speedX);
moveCube.transform.Translate(Vector3.up*Time.deltaTime*speedY);
dis += Time.deltaTime*speed;
if(dis>=s){
Debug.Log (moveCube.transform.position);
pIndex++;
//moveCube.transform.position = p;
if(pIndex<len){
moveCount();
}else{
moveFlag=0;
}
}
}
}
}
- Cube 逐点运动到点停止
- Cube逐点运动之动态增加节点
- 点到点协议
- 点到点协议
- 端到端与点到点
- 端到端,点到点
- python 点到点画线
- PPP(点到点协议)
- 点到点协议PPP
- 点到点距离
- iperf点到点测速
- 端到端的点到点区别
- 关于点到点和端到端
- PPTP------点到点隧道协议
- 计算机网络“点到点”与“端到端”
- Linux IPsec点到点配置
- 缓慢停止的运动
- 认识点到点和端到端通信
- String字符串与整数之间的相互转换
- Hihocoder 1039 : 字符消除
- 面试相关知识点(一)
- Geekband C++学习笔记——浅谈引用与指针
- 【BZOJ3622】已经没有什么好害怕的了,两次DP
- Cube 逐点运动到点停止
- c++头文件问题
- android 无法连接真机调试
- 算法代码实现之堆排序,Java实现
- hadoop 集群调度 Azkaban2搭建
- Uva10305——Ordering Tasks
- 使用 iframe 实现在同一页面中显示不同的内容
- SQL Server 之T-SQL语言的学习
- 22.1-7