示例#1
0
    private Vector3 Seperation(TestingSteering playerSteering)
    {
        Vector3 force         = new Vector3();
        int     neighborCount = 0;

        foreach (TestingSteering unit in _otherUnits)
        {
            if (unit != playerSteering &&
                Vector3.Distance(unit.CurrentPosition, playerSteering.CurrentPosition) <= _seperationDistance)
            {
                force += unit.CurrentPosition - playerSteering.CurrentPosition;

                neighborCount++;
            }
        }

        if (neighborCount != 0)
        {
            force /= neighborCount;

            force *= -1;
        }

        force.Normalize();
        force *= _maxSeperationDistance;

        return(force);
    }
示例#2
0
文件: LeaderFollow.cs 项目: bjck/AMFU
    private static Vector3 GetFollowPosition(TestingSteering leaderSteering)
    {
        Vector3 tv = leaderSteering.CurrentVelocity * -1;

        tv = tv.normalized * _followDistance;
        return(leaderSteering.CurrentPosition + tv);
    }
示例#3
0
    private Vector3 GetEvadeDirection(TestingSteering PlayerSteering, TestingSteering EvadeSteering)
    {
        Vector3 distance       = EvadeSteering.CurrentPosition - PlayerSteering.CurrentPosition;
        float   futureTime     = distance.magnitude / PlayerSteering.MoveMaxSpeed;
        Vector3 futurePosition = EvadeSteering.CurrentPosition + EvadeSteering.CurrentVelocity * futureTime;

        return(FleeBehaviour.GetDirectionVector(PlayerSteering.CurrentPosition, futurePosition));
    }
示例#4
0
    private Vector3 GetPursuitDirection(TestingSteering PlayerSteering, TestingSteering PursuitSteering)
    {
        Vector3 distance       = PursuitSteering.CurrentPosition - PlayerSteering.CurrentPosition;
        float   futureTime     = distance.magnitude / PlayerSteering.MoveMaxSpeed;
        Vector3 futurePosition = PursuitSteering.CurrentPosition + PursuitSteering.CurrentVelocity * futureTime;

        return(SeekBehaviour.GetDirectionVector(PlayerSteering.CurrentPosition, futurePosition));
    }
示例#5
0
文件: LeaderFollow.cs 项目: bjck/AMFU
    public static Vector3 GetDirectionVector(TestingSteering playerSteering, TestingSteering leaderSteering)
    {
        Vector3 followPosition = GetFollowPosition(leaderSteering);

        Vector3 force = SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, followPosition);

        //force += Seperation(playerSteering);

        return(force);
    }
示例#6
0
    private Vector3 GetFollowDirection(TestingSteering playerSteering, TestingSteering leaderSteering)
    {
        Vector3 tv = leaderSteering.CurrentVelocity * -1;

        tv = tv.normalized * _followDistance;
        Vector3 followPosition = leaderSteering.CurrentPosition + tv;

        Vector3 force = SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, followPosition);

        //force += Seperation(playerSteering);

        return(force);
    }
示例#7
0
    // Use this for initialization
    void Start()
    {
        _currentVelocity = Vector3.zero;

        if (_followSteering == null && _followTransform != null)
        {
            _followSteering = _followTransform.GetComponent <TestingSteering>();
            //_formationOffset = _followSteering.CurrentPosition - this.CurrentPosition;
            _formationOffset = this.CurrentPosition - _followSteering.CurrentPosition;
        }
        if (_otherUnits == null)
        {
            _otherUnits = new List <TestingSteering>(GameObject.FindObjectsOfType <TestingSteering>());
        }
    }
示例#8
0
    public static Vector3 GetFormationDirection(TestingSteering playerSteering, TestingSteering leaderSteering, Vector3 positionOffset)
    {
        Vector3 leadRot = leaderSteering.transform.rotation.eulerAngles;
        float   rot     = leadRot.y * Mathf.Deg2Rad;

        float cs = Mathf.Cos(rot);
        float sn = Mathf.Sin(rot);

        float newX = ((cs * positionOffset.x) - (sn * positionOffset.x));
        float newZ = ((sn * positionOffset.z) + (cs * positionOffset.z));

        Vector3 tmpPos = new Vector3(newX, 0, newZ);

        tmpPos += leaderSteering.CurrentPosition;

        //Vector3 tmpPos = leaderSteering.CurrentPosition + positionOffset;
        return(SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, tmpPos));
    }
示例#9
0
    private Vector3 GetPathDirection(TestingSteering playerSteering, Vector3 endPos, Graph graph)
    {
        //Should have a to Vector3 instead of using gridgenerator

        //Should maybe remember index of path, and only search again if end position changes
        //If not path is found, return old direction

        //Check if there is a direct path
        //Smooth path

        //Break pathfinding. Start from new, or continue on current path
        if (_currentEndPos != endPos)
        {
            if (graph != null)
            {
                _currentEndPos    = endPos;
                _currentPath      = HierarchicalAStar.FindPath(graph, this.CurrentPosition, _currentEndPos);
                _currentPathIndex = 0;
            }
        }
        if (_currentPath != null && _currentPath.Count > 1 && _currentPathIndex < _currentPath.Count)
        {
            nextPos   = _currentPath[_currentPathIndex];
            nextPos.y = this.CurrentPosition.y;
            if (Vector3.Distance(CurrentPosition, nextPos) < _distanceToNext)
            {
                if (_currentPathIndex < _currentPath.Count - 1)
                {
                    _currentPathIndex++;
                    nextPos = _currentPath[_currentPathIndex];
                }
                else
                {
                    nextPos = endPos;
                }
                nextPos.y = this.CurrentPosition.y;
            }
            return(GetSeekDirection(this.CurrentPosition, nextPos));
        }
        return(CurrentVelocity.normalized);
    }
示例#10
0
 public static Vector3 GetDirectionVector(TestingSteering playerSteering)
 {
     if (GridGenerator.level != null && GridGenerator._currentEnd != null)
     {
         Debug.Log("Finding path");
         List <Vector3> path = HierarchicalAStar.FindPath(GridGenerator.level, playerSteering.CurrentPosition - new Vector3(0, 1, 0), GridGenerator._currentEnd.transform.position);
         Debug.Log(path[1]);
         Vector3 nodePos = path[1];
         if (nodePos == Vector3.zero)
         {
             nodePos = path[2];
             if (nodePos == Vector3.zero)
             {
                 nodePos = path[3];
             }
         }
         Vector3 seekPosition = new Vector3(nodePos.x, playerSteering.CurrentPosition.y, nodePos.y);
         return(SeekBehaviour.GetDirectionVector(playerSteering.CurrentPosition, seekPosition));
     }
     return(Vector3.zero);
 }