Esempio n. 1
0
    public Vector3?SegmentIntersectionIndex(Vector3 A, Vector3 B, int index)
    {
        Vector3 fenceA = this.path[index];
        Vector3 fenceB = this.path[(index + 1) % this.path.Count];

        return(SegmentMath.SegmentSegmentIntersection(A, B, fenceA, fenceB));
    }
Esempio n. 2
0
    public static Vector3?SegmentPathIntersection(Vector3 A, Vector3 B, List <Vector3> path, bool closePath = true)
    {
        int iMax = path.Count - 1;

        if (closePath)
        {
            iMax += 1;
        }
        for (int i = 0; i < iMax; i++)
        {
            Vector3 C            = path[i];
            Vector3 D            = path[(i + 1) % path.Count];
            Vector3?intersection = SegmentMath.SegmentSegmentIntersection(A, B, C, D);
            if (intersection != null)
            {
                return(intersection);
            }
        }
        return(null);
    }
Esempio n. 3
0
    public void Update()
    {
        Vector3 previousPos = this.transform.position;

        this.transform.position += this.transform.forward * this.speed * Time.deltaTime;
        int     intersectionIndex;
        Vector3?fenceIntersection = this.fence.SegmentIntersection(previousPos, this.transform.position, out intersectionIndex);

        if (fenceIntersection != null)
        {
            Vector3 fenceDir    = this.fence.DirAt(intersectionIndex);
            Vector3 fenceNormal = this.fence.NormalAt(intersectionIndex);
            Vector3 newForward  = -Vector3.Dot(this.transform.forward, fenceNormal) * fenceNormal + Vector3.Dot(this.transform.forward, fenceDir) * fenceDir;
            this.transform.position = fenceIntersection.GetValueOrDefault() + fenceNormal * 0.05f;
            this.transform.rotation = Quaternion.LookRotation(newForward, Vector3.up);
        }
        Vector3?foxIntersection = SegmentMath.SegmentPathIntersection(previousPos, this.transform.position, this.fox.GetPath());

        if (foxIntersection != null)
        {
            Debug.LogWarning("You've hit by ! You've been struck by ! A smooth dog.");
            this.fox.isAlive = false;
        }
    }
Esempio n. 4
0
 public bool IsInside(Vector3 p)
 {
     return(SegmentMath.IsInsidePath(p, this.path));
 }