纳金网
标题:
坐标的表达
[打印本页]
作者:
may
时间:
2015-10-17 23:56
标题:
坐标的表达
====1===
物体A前后左右上下7米处坐标表达
Vector3 qian = A.transform.position + A.transform.forward * 7f;//物体A前方7米的坐标.
Vector3 hou = transform.position + (transform.rotation * Vector3.back)*7f;
Vector3 zuo = transform.position + (transform.rotation * Vector3.left)*7f;
Vector3 you = transform.position + transform.right * 7f;
Vector3 shang = transform.position + transform.up * 7f;
Vector3 xia = transform.position + (transform.rotation * Vector3.down)*7f;
Debug.DrawLine (transform.position,qian,Color.red);
Debug.DrawLine (transform.position,hou,Color.blue);
Debug.DrawLine (transform.position,zuo,Color.black);
Debug.DrawLine (transform.position,you,Color.green);
Debug.DrawLine (transform.position,shang,Color.gray);
Debug.DrawLine (transform.position,xia,Color.white);
=====2===
角色Y轴80度方向,前方5米处的坐标
float angle = 80f;
float length = 5f;
Quaternion q = Quaternion.Euler(transform.rotation.eulerAngles.x,angle, transform.rotation.eulerAngles.z); ///求出第i个点的旋转角度
Vector3 Point = transform.position +(q*transform.forward) * length;
更多注释
//360代表(360度,把360分成多少分,第几份).如果a = 4前方a=2后方a= 3右方a=1左方
//Quaternion q = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - (360/4 * a), transform.rotation.eulerAngles.z); ///求出第i个点的旋转角度
//运行代码
void Update ()
{
Vector3 qian = transform.position + transform.forward * 7f;
Vector3 hou = transform.position + (transform.rotation * Vector3.back)*7f;
Vector3 zuo = transform.position + (transform.rotation * Vector3.left)*7f;
Vector3 you = transform.position + transform.right * 7f;
Vector3 shang = transform.position + transform.up * 7f;
Vector3 xia = transform.position + (transform.rotation * Vector3.down)*7f;
Debug.DrawLine (transform.position,qian,Color.red);
Debug.DrawLine (transform.position,hou,Color.blue);
Debug.DrawLine (transform.position,zuo,Color.black);
Debug.DrawLine (transform.position,you,Color.green);
Debug.DrawLine (transform.position,shang,Color.gray);
Debug.DrawLine (transform.position,xia,Color.white);
float angle = 80f;
float length = 5f;
Quaternion q = Quaternion.Euler(transform.rotation.eulerAngles.x,angle, transform.rotation.eulerAngles.z); ///求出第i个点的旋转角度
Vector3 Point = transform.position +(q*transform.forward) * length;
Debug.DrawLine (transform.position, Point, Color.yellow);
}
作者:
moneyinwz
时间:
2015-10-26 10:41
好东西,谢谢分享
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5