Unity中的计算

1.在自身的前后:

   Vector3.Dot (transform.forward, target.position-transform.position)

      返回值为正时,目标在自己的前方,反之在后方

2.在自身的左右:

   Vector3.Dot(transform.right, target.position-transform.position)

      返回值为正时,目标在自己的右方,反之在左方

3.在自身上下:

   Vector3.Dot(transform.up, target.position-transform.position)

      返回值为正时,目标在自己的上方,反之在下方

4、Vector3 worldPosition = transform.TransformPoint ( Vector3 relativePosition )
将transform 的坐标转化为基于世界坐标系的坐标,相对位置为relativePosition(世界坐标系)

5、

        //     Calculate a position between the points specified by current and target, moving
        //     no farther than the distance specified by maxDistanceDelta.
        //
        // 参数:
        //   current:
        //     The position to move from.
        //
        //   target:
        //     The position to move towards.
        //
        //   maxDistanceDelta:
        //     Distance to move current per call.
        //
        // 返回结果:
        //     The new position.
        public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);

计算从current点,到target点的距离s,
如果距离s大于等于maxDistanceDelta,则最终点为从current开始,方向为current到target的方向,距离为maxDistanceDelta,最终计算出来的点
如果距离s小于maxDistanceDelta,则最终点为从current开始,方向为current到target的方向,距离为s,最终计算出来的点

     

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值