自动行为操控Steering(五)—拦截(单体操控)

图示:


实现:

public class InterceptSteering: Steering
    {
        public float safeDistance=15;
        public override Vector3 ComputerFinalForce()
        {
            float angle = Vector3.Angle((target.transform.position - this.transform.position).normalized, this.transform.forward.normalized);
            //if(Mathf.Acos(angle))

            //目标距离
            float distance = Vector3.Distance(target.transform.position, this.transform.position);
            //目标速度
            float targetSpeed = target.GetComponent<Vehicle>().currentForce.magnitude;
            //时间
            var time = distance / (speed + targetSpeed);
            //目标在推断时间内行走的距离=速度*时间
            var moveDistance = targetSpeed * time;
            //拦截点位置=目标自身位置+目标在推断时间内行走的距离
            Vector3 interceptPoint = target.transform.position + (target.transform.position).normalized * moveDistance;
            if (distance > safeDistance) return Vector3.zero;

            //期望=拦截点位置-自身位置
            exceptForce = (interceptPoint-transform.position ).normalized * speed;
            //实际=期望-当前
            return (exceptForce - vehicle.currentForce) * weight;
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值