- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
====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);
}
|
|