예제 #1
0
 void OnCollisionEnter(Collision collision)
 {
     if ((collision.collider.gameObject.layer & LayerMask.NameToLayer("Map")) != 0)
     {
         StartCoroutine(Collided());
         state = BUGState.Reverse;
     }
 }
예제 #2
0
    IEnumerator Collided()
    {
        accel    = -1f;
        steering = 0f;
        yield return(new WaitForSeconds(reverseTime));

        state = BUGState.Line;
        accel = 1f;
    }
예제 #3
0
    void FollowWall()
    {
        int ind = 0, step = 1;

        if (wallSide == Direction.Left)
        {
            ind  = 0;
            step = 1;
        }
        else if (wallSide == Direction.Right)
        {
            ind  = slices - 1;
            step = -1;
        }
        Vector3 normal = Vector3.zero;
        Vector3 target = Vector3.zero;

        while (ind >= 0 && ind < slices)
        {
            if (!isFree[ind])
            {
                float len = normalVectors[ind].magnitude;
                if (len > wallDistance)
                {
                    len = 0;
                }
                else
                {
                    len = len - wallDistance;
                }
                normal -= normalVectors[ind].normalized * len;
            }
            else
            {
                normal = normal.normalized;
                target = freeVectors[ind];
                break;
            }
            ind += step;
        }

        Vector3 tangent;
        bool    onPath  = OnPath(out tangent);
        Vector3 lineDir = tangent + lineVector * lineFollowDamp;
        int     sliceIndex;
        int     lineInd = ClosestVector(lasers.Vectors, lineDir, out sliceIndex);

        if (onPath && isFree[sliceIndex])
        {
            state = BUGState.Line;
        }
        direction = target + normal;
    }
예제 #4
0
    void FollowPath()
    {
        Vector3 tangent;
        bool    onPath = OnPath(out tangent);

        direction = tangent + lineVector * lineFollowDamp;

        int dirIndex;
        int sliceIndex;

        dirIndex = ClosestVector(lasers.Vectors, direction, out sliceIndex);
        if (!isFree[sliceIndex])
        {
            state = BUGState.Wall;
        }
    }
예제 #5
0
    void Start()
    {
        // Get components
        gps         = GetComponent <GPS>();
        lasers      = GetComponent <Lasers>();
        car         = GetComponent <CarController>();
        userControl = GetComponent <CarUserControl>();

        // Init state
        accel     = 1f;
        _slices   = 0;
        steering  = 0f;
        handbreak = 0f;
        state     = BUGState.Line;

        win     = false;
        newLine = true;
    }