示例#1
0
    private void UpdateLookAhead()
    {
        List <WorldAhead> newWorld = new List <WorldAhead>();

        foreach (WorldAhead ahead in worldAhead)
        {
            RaycastHit hitInfo;
            WorldAhead newAhead;
            if (Physics.Raycast(transform.position, ahead.lookAheadVector, out hitInfo))
            {
                Vector3 transformedLookAhead = transform.TransformDirection(ahead.lookAheadVector);

                Debug.DrawRay(transform.position, transformedLookAhead, Color.blue, 1.0f, false);

                newAhead = new WorldAhead(ahead.lookAheadVector, hitInfo);
            }
            else
            {
                newAhead = new WorldAhead(ahead.lookAheadVector);
            }

            newWorld.Add(newAhead);
        }
        worldAhead = newWorld;
    }
示例#2
0
 // returns Where the first location of obstacle type is detected ahead. Lots of infs if there is not obstacle of type  detected ahead.
 Vector3 WhereAhead(HaggisInteractable.InteractableType type, int maxDist)
 {
     for (int i = 0; i < worldAhead.Count && i < maxDist; ++i)
     {
         WorldAhead ahead = worldAhead[i];
         if (ahead.isHit)
         {
             if (ahead.type == type)
             {
                 return(ahead.position);
             }
         }
     }
     return(new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity));
 }
示例#3
0
 public WorldAhead WhatAhead(HaggisInteractable.InteractableType type, int maxDist)
 {
     for (int i = 0; i < worldAhead.Count && i < maxDist; ++i)
     {
         WorldAhead ahead = worldAhead[i];
         if (ahead.isHit)
         {
             if (ahead.type == type)
             {
                 return(ahead);
             }
         }
     }
     return(new WorldAhead(new Vector3(0.0f, 0.0f, 0.0f)));
 }
示例#4
0
    private void ConstructLookAheadVectors(int count)
    {
        worldAhead.Clear();
        for (int i = 0; i < count; ++i)
        {
            Vector3 lookAhead = Vector3.forward * (((float)i) / 2.0f);
            lookAhead -= Vector3.up;
            lookAhead.Normalize();

            // create empty world ahead
            WorldAhead ahead = new WorldAhead(lookAhead);
            worldAhead.Add(ahead);

            Debug.DrawRay(transform.position, lookAhead, Color.yellow, 10.0f, false);
        }
    }
示例#5
0
 // returns true if the obstacle type is detected ahead
 public bool IsAhead(HaggisInteractable.InteractableType type, int maxDist)
 {
     for (int i = 0; i < worldAhead.Count && i < maxDist; ++i)
     {
         WorldAhead ahead = worldAhead[i];
         if (ahead.isHit)
         {
             if (ahead.type == type)
             {
                 return(true);
             }
         }
         else if (type == HaggisInteractable.InteractableType.None)
         {
             return(true);
         }
     }
     return(false);
 }