unity3d 判断目标物体对于我的方向
2014-12-01 13:59
302 查看
using UnityEngine; using System.Collections; public class D2 : MonoBehaviour { public Transform targetTF; void Start () { } void Update () { checkTargetDirForMe (targetTF); } void checkTargetDirForMe(Transform target){ Vector3 dir = target.position - transform.position; Vector3 cross = Vector3.Cross (transform.forward,dir.normalized); float dot = Vector3.Dot (transform.forward,dir.normalized); string dirText = ""; if (cross.y > 0) { dirText += "右"; } else if(cross.y < 0) { dirText += "左"; }else { dirText += "正"; } if (dot > 0) { dirText += "上"; } else if(dot < 0) { dirText += "下"; }else { dirText += "中"; } print (dirText); } }
相关文章推荐
- unity3D基础学习 通过判断鼠标点击的是否是目标物体,物体旋转,滑动滚轮缩放拉近视角
- Unity3D里实现物体移动到目标点,并且摄像机跟着移动的简单方案
- 【Unity3D自学记录】判断物体是否在镜头内
- unity3d游戏物体跟着鼠标方向移动
- Unity3D中判断物体是否在摄像机视野中
- Unity3d 判断手势触摸的类型 ,判断手势的滑动方向,并获取刚触摸以及触摸结束事的坐标
- Unity3D中目标相对自身的前后左右方位判断
- [unity3d]判断物体是否在视角内(巧妙的一篇转载)
- Unity3D中目标相对自身的前后左右方位判断
- unity3d 判断敌人在我的前后方向
- Unity3d 射线测试+使用手势判断是否触碰了某物体
- 【UE4】【C++】判断是否撞击到物体、从蓝图中获取组件(炮管、炮塔)、根据瞄准的方向进行(角色)旋转
- unity3d点击屏幕判断是否击中场景中物体
- 关于Unity3D判断物体是否在视角内(巧妙!)
- 【Unity3D】判断是否鼠标点击物体与血条制作
- Unity3D中物体绕垂直于鼠标划过方向的轴的旋转
- 【Unity3D自学记录】判断物体是否在镜头内
- Unity3D里实现物体移动到目标点,并且摄像机跟着移动的简单方案
- Unity3D中目标相对自身的前后左右方位判断
- unity3d游戏物体跟着鼠标方向移动