图示:
实现:
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;
}
}