Unity判断目标在哪个方向

int pointIndex=0;//表示下标
Gamectrl._Instance.pathArr;//表示一个点位数组

        //向目标点移动
        transform.localPosition = Vector3.MoveTowards(transform.localPosition, Gamectrl._Instance.pathArr[pointIndex].localPosition, Time.deltaTime * playerMoveSpeed +chongciSpeed);
        //判断豆豆与点的距离
        if (Vector2.Distance(transform.localPosition, Gamectrl._Instance.pathArr[pointIndex].localPosition) < 1f)
        {
            //下一个点
            pointIndex++;


            dir = Gamectrl._Instance.pathArr[pointIndex].localPosition - transform.localPosition;
            //Debug.Log(dir+"   "+Vector3.Dot(transform.forward, dir));

			//使用点乘   差乘
            if (Vector3.Dot(transform.up,dir)>10)
            {
                //Debug.Log("上");
                /**
                PlayerChange(0);
                fire.transform.SetParent(playerArr[0].transform);
                fire.transform.localPosition= new Vector3(-0.3f, 0, 0);
                fire.transform.localRotation = Quaternion.Euler(0, 0, -180);
                fire.transform.localScale = Vector3.one;
                moveType = MoveType.Up;
                */
            }
            else if (Vector3.Dot(transform.up, dir) < -10)
            {
                //Debug.Log("下");
                /**
                PlayerChange(1);
                fire.transform.SetParent(playerArr[1].transform);
                fire.transform.localPosition = new Vector3(-0.3f, 0, 0);
                fire.transform.localRotation = Quaternion.Euler(0, 0, 180);
                fire.transform.localScale = Vector3.one;
                moveType = MoveType.Down;
                */
            }
            else if(Vector3.Cross(transform.forward, dir).y > 10)
            {
                 //Debug.Log("右");
                /**
                PlayerChange(3);
                fire.transform.SetParent(playerArr[3].transform);
                fire.transform.localPosition = new Vector3(0.3f, 0, 0);
                fire.transform.localRotation = Quaternion.Euler(0, 0, 0);
                fire.transform.localScale = Vector3.one;
                moveType = MoveType.Right;
                */
            }
            else if (Vector3.Cross(transform.forward, dir).y < -10)
            {
                //Debug.Log("左");
                /**
                PlayerChange(2);
                fire.transform.SetParent(playerArr[2].transform);
                fire.transform.localPosition = new Vector3(-0.3f, 0, 0);
                fire.transform.localRotation = Quaternion.Euler(180, 0, 180);
                fire.transform.localScale = Vector3.one;
                moveType = MoveType.Left;
                */
            }

        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值