Beispiel #1
0
    void Update()
    {
        bool addControlThreshold = false;

        if (player != null)
        {
            Vector3 input = player.GetInputAxis();
            if (input.magnitude >= MinControlMagnitude)
            {
                addControlThreshold = true;
            }
        }

        if (addControlThreshold)
        {
            controlThreshold += Time.deltaTime;
        }
        else
        {
            controlThreshold -= Time.deltaTime;
        }
        controlThreshold = Mathf.Clamp(controlThreshold, 0f, MaxControlThreshold);

        if (player != null && controlThreshold >= MinControlThreshold)
        {
            MovePlayer();
            if (Vector3.Distance(lastPointPosition, transform.position) >= DistanceBetweenPointPositions)
            {
                // Create.
                currentAntPoint   = antPointManager.AddPoint(transform.position, currentAntPoint);
                lastPointPosition = transform.position;
            }
        }
        else
        {
            // Wander around using AI.
            if (currentAntPoint == null)
            {
                currentAntPoint = antPointManager.GetNearestAntPoint(transform.position, PointSearchDistance);
            }

            if (currentAntPoint != null)
            {
                pointFollower.TowardsPoint(currentAntPoint.Position);
                Vector3 toTarget = currentAntPoint.Position - transform.position;
                toTarget.z = 0f;
                if (toTarget.magnitude <= NextPointDistance)
                {
                    currentAntPoint = currentAntPoint.GetNextPoint();
                }
            }
        }
    }
Beispiel #2
0
    public MiniBugs_AntPoint AddPoint(Vector3 pos, MiniBugs_AntPoint fromPoint)
    {
        MiniBugs_AntPoint newPoint = new MiniBugs_AntPoint(pos, fromPoint);

        AntPoints.Add(newPoint);
        if (fromPoint != null)
        {
            fromPoint.ToPoints.Add(newPoint);
        }

        return(newPoint);
    }
    public void OnSceneGUI()
    {
        apm = this.target as MiniBugs_AntPointManager;
        for (int i = 0; i < apm.AntPoints.Count; i++)
        {
            MiniBugs_AntPoint p = apm.AntPoints[i];
            Handles.DrawWireDisc(
                p.Position,
                Vector3.forward,
                1f
                );

            for (int j = 0; j < apm.AntPoints[i].ToPoints.Count; j++)
            {
                Handles.DrawLine(
                    apm.AntPoints[i].ToPoints[j].Position,
                    apm.AntPoints[i].Position
                    );
            }
        }
    }
Beispiel #4
0
    public MiniBugs_AntPoint GetNearestAntPoint(Vector3 pos, float radius)
    {
        if (AntPoints.Count > 0)
        {
            MiniBugs_AntPoint closest = null;
            float             dist    = 0f;
            foreach (MiniBugs_AntPoint point in AntPoints)
            {
                Vector3 to = pos - point.Position;
                to.z = 0f;
                if (to.magnitude <= radius && (closest == null || to.magnitude < dist))
                {
                    closest = point;
                    dist    = to.magnitude;
                }
            }

            return(closest);
        }
        else
        {
            return(null);
        }
    }
Beispiel #5
0
 public MiniBugs_AntPoint(Vector3 position, MiniBugs_AntPoint fromPoint)
 {
     this.Position  = position;
     this.FromPoint = fromPoint;
 }