Exemple #1
0
    public void SetTargetPath(FSMPath path, int targetSpeed, float heightOffset)
    {
        _heightOffset = heightOffset;

        // Ignore instruction if path is the current path.
        if (path == _currentPath)
        {
            return;
        }

        // Check which end of the path is closest.
        // This is correct if you look at the training mission - there are two cars that share the same path from opposite ends.
        Vector3 pos       = transform.position;
        Vector3 worldPos  = GameObject.Find("World").transform.position;
        Vector3 pathStart = worldPos + path.Nodes[0].ToVector3();
        Vector3 pathEnd   = worldPos + path.Nodes[path.Nodes.Length - 1].ToVector3();

        float startDistance = Vector3.Distance(pos, pathStart);
        float endDistance   = Vector3.Distance(pos, pathEnd);

        if (startDistance < endDistance)
        {
            _nodeIndex    = 0;
            _pathReversed = false;
        }
        else
        {
            _nodeIndex    = path.Nodes.Length - 1;
            _pathReversed = true;
        }

        _currentPath = path;
        _targetSpeed = targetSpeed;
        _targetPos   = new Vector2(worldPos.x + path.Nodes[_nodeIndex].x, worldPos.z + path.Nodes[_nodeIndex].z);
    }
Exemple #2
0
 public void SetTargetPath(FSMPath path, int targetSpeed)
 {
     if (AI != null)
     {
         AI.SetTargetPath(path, targetSpeed);
     }
 }
Exemple #3
0
        public bool IsWithinNav(FSMPath path, int distance)
        {
            I76Vector3[] nodes         = path.Nodes;
            int          nodeCountMin1 = nodes.Length - 1;

            Vector3 worldPos = _worldTransform.position;
            Vector3 carPos   = _transform.position;
            Vector2 pos2D    = new Vector2(carPos.x, carPos.z);

            if (nodeCountMin1 == 0)
            {
                Vector2 nodePos;
                nodePos.x = worldPos.x + nodes[0].x;
                nodePos.y = worldPos.z + nodes[0].z;
                return(Vector2.Distance(nodePos, pos2D) < distance);
            }

            for (int i = 0; i < nodeCountMin1; ++i)
            {
                Vector2 nodeStart, nodeEnd;
                nodeStart.x = worldPos.x + nodes[i].x;
                nodeStart.y = worldPos.z + nodes[i].z;
                nodeEnd.x   = worldPos.x + nodes[i + 1].x;
                nodeEnd.y   = worldPos.z + nodes[i + 1].z;

                float navDistance = Utils.DistanceFromPointToLine(nodeStart, nodeEnd, pos2D);
                if (navDistance < distance)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        public bool IsWithinNav(FSMPath path, int distance)
        {
            if (AI != null)
            {
                return(AI.IsWithinNav(path, distance));
            }

            return(false);
        }
Exemple #5
0
    private void NextWaypoint()
    {
        _nodeIndex += _pathReversed ? -1 : 1;

        if (_nodeIndex < 0 || _nodeIndex == _currentPath.Nodes.Length)
        {
            Arrived      = true;
            _currentPath = null;
        }
        else
        {
            Vector3 worldPos = _worldTransform.position;
            _targetPos.x = worldPos.x + _currentPath.Nodes[_nodeIndex].x;
            _targetPos.y = worldPos.z + _currentPath.Nodes[_nodeIndex].z;
        }
    }
Exemple #6
0
        private void NextWaypoint()
        {
            _nodeIndex += _pathReversed ? -1 : 1;

            if (_nodeIndex < 0 || _nodeIndex == _currentPath.Nodes.Length)
            {
                _controller.Arrived  = true;
                _currentPath         = null;
                _currentRoad         = null;
                _carPhysics.Throttle = 0.0f;
            }
            else
            {
                Vector3 worldPos = _worldTransform.position;
                _targetPos.x = worldPos.x + _currentPath.Nodes[_nodeIndex].x;
                _targetPos.y = worldPos.z + _currentPath.Nodes[_nodeIndex].z;
            }
        }
Exemple #7
0
        public void SetFollowTarget(Car car, int xOffset, int targetSpeed)
        {
            _targetSpeed   = targetSpeed;
            _followXOffset = xOffset;

            if (_followTarget == car)
            {
                return;
            }

            _followTarget = null;
            _currentPath  = null;

            if (!car.Alive)
            {
                return;
            }

            _followTarget = car;
        }
Exemple #8
0
 public void Sit()
 {
     _currentPath = null;
 }