Esempio n. 1
0
 public void Steer(SteerInfo info)
 {
     for (int i = 0; i < info.Count; ++i) {
         var d = transform.TransformDirection(info.Direction(i));
         var ray = new Ray(transform.position, d);
         RaycastHit hit;
         if (Physics.SphereCast(new Ray(transform.position,info.Direction(i)), 0.1f,out hit,Mathf.Infinity)) {
             info.SetAvoid(i, 1 / (1+hit.distance - skinWidth));
         }
     }
 }
Esempio n. 2
0
    void Steer(SteerInfo info)
    {
        if(target == null) return;

        for (int i = 0; i < info.Count; ++i) {
            var d = transform.TransformDirection(info.Direction(i));
            var diff = target.position - transform.position;
            var dot = Vector3.Dot(d, diff.normalized);
            var dist = diff.magnitude;
            info.SetSeek(i, Mathf.Clamp01(dot*strength * Mathf.Clamp01(dist / 5)));
        }
    }
Esempio n. 3
0
 public void Steer(SteerInfo info)
 {
     for (int i = 0; i < info.Count; ++i)
     {
         var        d   = transform.TransformDirection(info.Direction(i));
         var        ray = new Ray(transform.position, d);
         RaycastHit hit;
         if (Physics.SphereCast(new Ray(transform.position, info.Direction(i)), 0.1f, out hit, Mathf.Infinity))
         {
             info.SetAvoid(i, 1 / (1 + hit.distance - skinWidth));
         }
     }
 }
Esempio n. 4
0
    void Steer(SteerInfo info)
    {
        if (target == null)
        {
            return;
        }

        for (int i = 0; i < info.Count; ++i)
        {
            var d    = transform.TransformDirection(info.Direction(i));
            var diff = target.position - transform.position;
            var dot  = Vector3.Dot(d, diff.normalized);
            var dist = diff.magnitude;
            info.SetSeek(i, Mathf.Clamp01(dot * strength * Mathf.Clamp01(dist / 5)));
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        var info = new SteerInfo() {
            avoid = new float[directionCount],
            seek = new float[directionCount]
        };

        BroadcastMessage("Steer", info, SendMessageOptions.DontRequireReceiver);

        var dir = (
            from i in Enumerable.Range(0, directionCount)
            let s = info.seek[i]
            let a = 1 - info.avoid[i]
            let d = info.Direction(i)
            let v = Mathf.Min(a, s)
            where v > 0.001f
            orderby v descending
            select d * a)
            .FirstOrDefault();

        BroadcastMessage("Move", dir);
    }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        var info = new SteerInfo()
        {
            avoid = new float[directionCount],
            seek  = new float[directionCount]
        };

        BroadcastMessage("Steer", info, SendMessageOptions.DontRequireReceiver);

        var dir = (
            from i in Enumerable.Range(0, directionCount)
            let s = info.seek[i]
                    let a = 1 - info.avoid[i]
                            let d = info.Direction(i)
                                    let v = Mathf.Min(a, s)
                                            where v > 0.001f
                                            orderby v descending
                                            select d * a)
                  .FirstOrDefault();

        BroadcastMessage("Move", dir);
    }