Пример #1
0
    // we determine the lane by considering the angle between the previous target
    // and the 2nd next waypoint:
    // (2) ---- (3)
    //  |
    //  |
    // (1)
    // when travelling (1) -> (2), we'll need to keep to the right-most lane as we'll be turning right.
    private int DetermineLane(LaneConfiguration lc, Vector3 direction, out Vector3 willTurn)
    {
        // there is no previous waypoint
        willTurn = Vector3.zero;
        if (headingToIndex == 0)
        {
            return(1);
        }

        // if there is no next
        if (headingToIndex + 1 == path.Length)
        {
            return(1);
        }

        var previous = path[headingToIndex - 1].transform.position;
        var next     = path[headingToIndex + 1].transform.position;

        var heading   = next - previous;
        var distance  = heading.magnitude;
        var targetDir = heading / distance; // This is now the normalized direction.

        var relativeDir = XVector3.AngleDir(direction, targetDir, Vector3.up);

        willTurn = relativeDir;

        return(relativeDir == Vector3.left ? lc.LeftMost() : lc.RightMost());
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        spawnDelay = Mathf.Pow(SpawnsPerMinute * GlobalRatio / 60f, -1);

        directionToNeighbour = XVector3.Direction(wp.transform.position, wp.Neighbours[0].transform.position);
        lc = TCA.GetLaneConfiguration(wp, wp.Neighbours[0]);

        InitLanes();

        StartCoroutine(WaitSpawn());
    }
 private bool FindLaneConf(Waypoint from, Waypoint to, out LaneConfiguration lc)
 {
     foreach (var laneConf in laneConfigurations)
     {
         if (laneConf.From == from && laneConf.To == to)
         {
             lc = laneConf;
             return(true);
         }
     }
     lc = default(LaneConfiguration);
     return(false);
 }
    private LaneConfiguration CreateReverse(LaneConfiguration lc)
    {
        var midPoint = (lc.To.transform.position - lc.From.transform.position) * 0.5f;

        midPoint += lc.From.transform.position;

        var nlcGameObject = Instantiate(LaneConfigurationPrefab, midPoint, Quaternion.identity, WaypointContainer.transform);

        nlcGameObject.name = "LaneConfiguration-Reverse";

        var nlc = nlcGameObject.GetComponent <LaneConfiguration>();

        nlc.From       = lc.To;
        nlc.To         = lc.From;
        nlc.LeftLanes  = lc.RightLanes;
        nlc.RightLanes = lc.LeftLanes;

        return(nlc);
    }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     LC = gameObject.GetComponent <LaneConfiguration> ();
     StartCoroutine(WaitAndClose());
 }