Пример #1
0
        /*
         * <summary>Recalculates all nodes to build a path from a given starting position</summary>
         * <param name = "startPosition">The position to start from</param>
         * <param name = "maxNodeDistance">If >0, the maximum allowed distance between two nodes</param>
         */
        public void RecalculateToCenter(Vector3 startPosition, float maxNodeDistance = -1f)
        {
            Vector3[] pointArray;
            Vector3   targetPosition = startPosition;

            if (SceneSettings.ActInScreenSpace())
            {
                targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
            }

            if (KickStarter.navigationManager != null)
            {
                pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(transform.position, targetPosition);
            }
            else
            {
                List <Vector3> pointList = new List <Vector3>();
                pointList.Add(targetPosition);
                pointArray = pointList.ToArray();
            }

            pointArray = SetMaxDistances(pointArray, maxNodeDistance);

            BuildNavPath(pointArray);
            pathType = AC_PathType.ReverseOnly;
        }
Пример #2
0
        protected void FollowUpdate()
        {
            followUpdateTimer = followFrequency;

            float dist = FollowCheckDistance();

            if (dist > followDistance)
            {
                Paths path = GetComponent <Paths>();
                if (path == null)
                {
                    ACDebug.LogWarning("Cannot move a character with no Paths component", gameObject);
                }
                else
                {
                    path.pathType = AC_PathType.ForwardOnly;
                    path.affectY  = true;

                    Vector3[] pointArray;
                    Vector3   targetPosition = followTarget.Transform.position;

                    if (SceneSettings.ActInScreenSpace())
                    {
                        targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                    }

                    if (KickStarter.navigationManager)
                    {
                        if (followRandomDirection)
                        {
                            targetPosition = KickStarter.navigationManager.navigationEngine.GetPointNear(targetPosition, followDistance, followDistanceMax);
                        }
                        pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(Transform.position, targetPosition, this);
                    }
                    else
                    {
                        List <Vector3> pointList = new List <Vector3>();
                        pointList.Add(targetPosition);
                        pointArray = pointList.ToArray();
                    }

                    if (dist > followDistanceMax)
                    {
                        MoveAlongPoints(pointArray, true);
                    }
                    else
                    {
                        MoveAlongPoints(pointArray, false);
                    }
                    isEvadingPlayer = false;
                }
            }
        }
Пример #3
0
        override public void Skip()
        {
            if (runtimeChar != null && runtimeMarker != null)
            {
                runtimeChar.EndPath();

                if (runtimeChar is NPC)
                {
                    NPC npcToMove = (NPC)runtimeChar;
                    npcToMove.StopFollowing();
                }

                Vector3[] pointArray;
                Vector3   targetPosition = runtimeMarker.transform.position;

                if (SceneSettings.ActInScreenSpace())
                {
                    targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                }

                if (pathFind && KickStarter.navigationManager)
                {
                    pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(runtimeChar.transform.position, targetPosition);
                    KickStarter.navigationManager.navigationEngine.ResetHoles(KickStarter.sceneSettings.navMesh);
                }
                else
                {
                    List <Vector3> pointList = new List <Vector3>();
                    pointList.Add(targetPosition);
                    pointArray = pointList.ToArray();
                }

                int i = pointArray.Length - 1;

                if (i > 0)
                {
                    runtimeChar.SetLookDirection(pointArray[i] - pointArray[i - 1], true);
                }
                else
                {
                    runtimeChar.SetLookDirection(pointArray[i] - runtimeChar.transform.position, true);
                }

                runtimeChar.Teleport(pointArray [i]);

                if (faceAfter)
                {
                    runtimeChar.SetLookDirection(runtimeMarker.transform.forward, true);
                }
            }
        }
Пример #4
0
        /**
         * Places the Player at the GameObject's position, and activates the assigned cameraOnStart.
         */
        public void PlacePlayerAt()
        {
            if (KickStarter.mainCamera)
            {
                if (fadeInOnStart)
                {
                    KickStarter.mainCamera.FadeIn(fadeSpeed);
                }

                if (KickStarter.settingsManager)
                {
                    if (KickStarter.player)
                    {
                        KickStarter.player.SetLookDirection(ForwardDirection, true);
                        KickStarter.player.Teleport(KickStarter.sceneChanger.GetStartPosition(Position));

                        if (SceneSettings.ActInScreenSpace())
                        {
                            KickStarter.player.Transform.position = AdvGame.GetScreenNavMesh(KickStarter.player.Transform.position);
                        }
                    }

                    if (KickStarter.settingsManager.movementMethod == MovementMethod.FirstPerson)
                    {
                        KickStarter.mainCamera.SetFirstPerson();
                    }
                    else if (cameraOnStart)
                    {
                        SetCameraOnStart();
                    }
                    else
                    {
                        if (!KickStarter.settingsManager.IsInFirstPerson())
                        {
                            ACDebug.LogWarning("PlayerStart '" + gameObject.name + "' has no Camera On Start", this);

                            if (KickStarter.sceneSettings != null &&
                                this != KickStarter.sceneSettings.defaultPlayerStart)
                            {
                                KickStarter.sceneSettings.defaultPlayerStart.SetCameraOnStart();
                            }
                        }
                    }

                    KickStarter.eventManager.Call_OnOccupyPlayerStart(KickStarter.player, this);
                }
            }
        }
Пример #5
0
        /**
         * Places the Player at the GameObject's position, and activates the assigned cameraOnStart.
         */
        public void SetPlayerStart()
        {
            if (KickStarter.mainCamera)
            {
                if (fadeInOnStart)
                {
                    KickStarter.mainCamera.FadeIn(fadeSpeed);
                }

                if (KickStarter.settingsManager)
                {
                    if (KickStarter.player)
                    {
                        KickStarter.player.Teleport(KickStarter.sceneChanger.GetStartPosition(this.transform.position));
                        KickStarter.player.SetLookDirection(this.transform.forward, true);

                        if (KickStarter.settingsManager.ActInScreenSpace() && !KickStarter.settingsManager.IsUnity2D())
                        {
                            KickStarter.player.transform.position = AdvGame.GetScreenNavMesh(KickStarter.player.transform.position);
                        }
                    }

                    if (KickStarter.settingsManager.movementMethod == MovementMethod.FirstPerson)
                    {
                        KickStarter.mainCamera.SetFirstPerson();
                    }
                    else if (cameraOnStart != null)
                    {
                        SetCameraOnStart();
                    }
                    else
                    {
                        if (!KickStarter.settingsManager.IsInFirstPerson())
                        {
                            ACDebug.LogWarning(this.name + " has no Camera On Start", this);

                            if (KickStarter.sceneSettings != null &&
                                this != KickStarter.sceneSettings.defaultPlayerStart)
                            {
                                KickStarter.sceneSettings.defaultPlayerStart.SetCameraOnStart();
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        private void FollowMove()
        {
            float dist = FollowCheckDistance();

            if (dist > followDistance)
            {
                Paths path = GetComponent <Paths>();
                if (path == null)
                {
                    ACDebug.LogWarning("Cannot move a character with no Paths component");
                }
                else
                {
                    path.pathType = AC_PathType.ForwardOnly;
                    path.affectY  = true;

                    Vector3[] pointArray;
                    Vector3   targetPosition = followTarget.transform.position;

                    if (KickStarter.settingsManager && KickStarter.settingsManager.ActInScreenSpace())
                    {
                        targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                    }

                    if (KickStarter.navigationManager)
                    {
                        pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(transform.position, targetPosition, this);
                    }
                    else
                    {
                        List <Vector3> pointList = new List <Vector3>();
                        pointList.Add(targetPosition);
                        pointArray = pointList.ToArray();
                    }

                    if (dist > followDistanceMax)
                    {
                        MoveAlongPoints(pointArray, true);
                    }
                    else
                    {
                        MoveAlongPoints(pointArray, false);
                    }
                }
            }
        }
        override public void Skip()
        {
            if (charToMove && marker)
            {
                charToMove.EndPath();

                if (charToMove is NPC)
                {
                    NPC npcToMove = (NPC)charToMove;
                    npcToMove.StopFollowing();
                }

                Vector3[] pointArray;
                Vector3   targetPosition = marker.transform.position;

                if (KickStarter.settingsManager.ActInScreenSpace())
                {
                    targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                }

                if (pathFind && KickStarter.navigationManager)
                {
                    pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(charToMove.transform.position, targetPosition);
                    KickStarter.navigationManager.navigationEngine.ResetHoles(KickStarter.sceneSettings.navMesh);
                }
                else
                {
                    List <Vector3> pointList = new List <Vector3>();
                    pointList.Add(targetPosition);
                    pointArray = pointList.ToArray();
                }

                int i = pointArray.Length - 1;

                if (i > 0)
                {
                    charToMove.SetLookDirection(pointArray[i] - pointArray[i - 1], true);
                }
                else
                {
                    charToMove.SetLookDirection(pointArray[i] - charToMove.transform.position, true);
                }

                charToMove.Teleport(pointArray [i]);
            }
        }
Пример #8
0
        public void SetPlayerStart()
        {
            if (KickStarter.mainCamera)
            {
                if (fadeInOnStart)
                {
                    KickStarter.mainCamera.FadeIn(fadeSpeed);
                }

                if (KickStarter.settingsManager)
                {
                    if (KickStarter.player)
                    {
                        KickStarter.player.Teleport(this.transform.position);
                        KickStarter.player.SetLookDirection(this.transform.forward, true);

                        if (KickStarter.settingsManager.ActInScreenSpace() && !KickStarter.settingsManager.IsUnity2D())
                        {
                            KickStarter.player.transform.position = AdvGame.GetScreenNavMesh(KickStarter.player.transform.position);
                        }
                    }

                    if (KickStarter.settingsManager.movementMethod == MovementMethod.FirstPerson)
                    {
                        KickStarter.mainCamera.SetFirstPerson();
                    }

                    else if (cameraOnStart)
                    {
                        KickStarter.mainCamera.SetGameCamera(cameraOnStart);
                        KickStarter.mainCamera.lastNavCamera = cameraOnStart;
                        cameraOnStart.MoveCameraInstant();
                        KickStarter.mainCamera.SetGameCamera(cameraOnStart);
                        KickStarter.mainCamera.SnapToAttached();
                    }

                    else if (cameraOnStart == null)
                    {
                        if (!KickStarter.settingsManager.IsInFirstPerson())
                        {
                            Debug.LogWarning(this.name + " has no Camera On Start");
                        }
                    }
                }
            }
        }
Пример #9
0
        private Vector3[] TryNavPoint(Vector3 _direction)
        {
            Vector3 _targetPosition = transform.position + _direction.normalized * minPlayerDistance * 1.2f;

            if (KickStarter.settingsManager.ActInScreenSpace())
            {
                _targetPosition = AdvGame.GetScreenNavMesh(_targetPosition);
            }
            else if (KickStarter.settingsManager.cameraPerspective == CameraPerspective.ThreeD)
            {
                _targetPosition.y = transform.position.y;
            }

            Vector3[] pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(transform.position, _targetPosition, this);
            if (Vector3.Distance(pointArray [pointArray.Length - 1], transform.position) < minPlayerDistance * 0.6f)
            {
                // Not far away enough
                return(null);
            }
            return(pointArray);
        }
Пример #10
0
        protected Vector3[] TryNavPoint(Vector3 _direction)
        {
            float   currentDistance = _direction.magnitude;
            Vector3 _targetPosition = Transform.position + _direction.normalized * (minPlayerDistance - currentDistance) * 1.2f;

            if (SceneSettings.ActInScreenSpace())
            {
                _targetPosition = AdvGame.GetScreenNavMesh(_targetPosition);
            }
            else if (SceneSettings.CameraPerspective == CameraPerspective.ThreeD)
            {
                _targetPosition.y = Transform.position.y;
            }

            Vector3[] pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(Transform.position, _targetPosition, this);

            if (pointArray.Length == 0 || Vector3.Distance(pointArray [pointArray.Length - 1], Transform.position) < minPlayerDistance * 0.6f)
            {
                // Not far away enough
                return(null);
            }
            return(pointArray);
        }
Пример #11
0
        override public float Run()
        {
            if (!isRunning)
            {
                if (runtimeChar != null && runtimeMarker != null)
                {
                    isRunning = true;

                    Paths path = runtimeChar.GetComponent <Paths>();
                    if (path == null)
                    {
                        ACDebug.LogWarning("Cannot move a character with no Paths component", runtimeChar);
                    }
                    else
                    {
                        if (runtimeChar is NPC)
                        {
                            NPC npcToMove = (NPC)runtimeChar;
                            npcToMove.StopFollowing();
                        }

                        path.pathType  = AC_PathType.ForwardOnly;
                        path.pathSpeed = speed;
                        path.affectY   = true;

                        Vector3[] pointArray;
                        Vector3   targetPosition = runtimeMarker.transform.position;

                        if (SceneSettings.ActInScreenSpace())
                        {
                            targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                        }

                        float distance = Vector3.Distance(targetPosition, runtimeChar.transform.position);
                        if (distance <= KickStarter.settingsManager.GetDestinationThreshold())
                        {
                            isRunning = false;
                            return(0f);
                        }

                        if (pathFind && KickStarter.navigationManager)
                        {
                            pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(runtimeChar.transform.position, targetPosition, runtimeChar);
                        }
                        else
                        {
                            List <Vector3> pointList = new List <Vector3>();
                            pointList.Add(targetPosition);
                            pointArray = pointList.ToArray();
                        }

                        if (speed == PathSpeed.Walk)
                        {
                            runtimeChar.MoveAlongPoints(pointArray, false, pathFind);
                        }
                        else
                        {
                            runtimeChar.MoveAlongPoints(pointArray, true, pathFind);
                        }

                        if (runtimeChar.GetPath())
                        {
                            if (!pathFind && doFloat)
                            {
                                runtimeChar.GetPath().affectY = true;
                            }
                            else
                            {
                                runtimeChar.GetPath().affectY = false;
                            }
                        }

                        if (willWait)
                        {
                            currentTimer = maxTime;
                            return(defaultPauseTime);
                        }
                    }
                }

                return(0f);
            }
            else
            {
                if (runtimeChar.GetPath() == null)
                {
                    if (faceAfter)
                    {
                        if (!isFacingAfter)
                        {
                            isFacingAfter = true;
                            runtimeChar.SetLookDirection(runtimeMarker.transform.forward, false);
                            return(defaultPauseTime);
                        }
                        else
                        {
                            if (runtimeChar.IsTurning())
                            {
                                return(defaultPauseTime);
                            }
                        }
                    }

                    isRunning = false;
                    return(0f);
                }
                else
                {
                    if (doTimeLimit)
                    {
                        currentTimer -= Time.deltaTime;
                        if (currentTimer <= 0)
                        {
                            switch (onReachTimeLimit)
                            {
                            case OnReachTimeLimit.StopMoving:
                                runtimeChar.EndPath();
                                break;

                            case OnReachTimeLimit.TeleportToDestination:
                                Skip();
                                break;
                            }

                            isRunning = false;
                            return(0f);
                        }
                    }

                    return(defaultPauseTime);
                }
            }
        }
Пример #12
0
        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;

                if (charToMove && marker)
                {
                    Paths path = charToMove.GetComponent <Paths>();
                    if (path == null)
                    {
                        ACDebug.LogWarning("Cannot move a character with no Paths component");
                    }
                    else
                    {
                        if (charToMove is NPC)
                        {
                            NPC npcToMove = (NPC)charToMove;
                            npcToMove.StopFollowing();
                        }

                        path.pathType  = AC_PathType.ForwardOnly;
                        path.pathSpeed = speed;
                        path.affectY   = true;

                        Vector3[] pointArray;
                        Vector3   targetPosition = marker.transform.position;

                        if (SceneSettings.ActInScreenSpace())
                        {
                            targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                        }

                        if (pathFind && KickStarter.navigationManager)
                        {
                            pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(charToMove.transform.position, targetPosition, charToMove);
                        }
                        else
                        {
                            List <Vector3> pointList = new List <Vector3>();
                            pointList.Add(targetPosition);
                            pointArray = pointList.ToArray();
                        }

                        if (speed == PathSpeed.Walk)
                        {
                            charToMove.MoveAlongPoints(pointArray, false, pathFind);
                        }
                        else
                        {
                            charToMove.MoveAlongPoints(pointArray, true, pathFind);
                        }

                        if (charToMove.GetPath())
                        {
                            if (!pathFind && doFloat)
                            {
                                charToMove.GetPath().affectY = true;
                            }
                            else
                            {
                                charToMove.GetPath().affectY = false;
                            }
                        }

                        if (willWait)
                        {
                            currentTimer = maxTime;
                            return(defaultPauseTime);
                        }
                    }
                }

                return(0f);
            }
            else
            {
                if (charToMove.GetPath() == null)
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    if (doTimeLimit)
                    {
                        currentTimer -= Time.deltaTime;
                        if (currentTimer <= 0)
                        {
                            switch (onReachTimeLimit)
                            {
                            case OnReachTimeLimit.StopMoving:
                                charToMove.EndPath();
                                break;

                            case OnReachTimeLimit.TeleportToDestination:
                                Skip();
                                break;
                            }

                            isRunning = false;
                            return(0f);
                        }
                    }

                    return(defaultPauseTime);
                }
            }
        }
Пример #13
0
        override public float Run()
        {
            if (!isRunning)
            {
                isRunning = true;

                if (charToMove && marker)
                {
                    Paths path = charToMove.GetComponent <Paths>();
                    if (path == null)
                    {
                        Debug.LogWarning("Cannot move a character with no Paths component");
                    }
                    else
                    {
                        if (charToMove is NPC)
                        {
                            NPC npcToMove = (NPC)charToMove;
                            npcToMove.FollowReset();
                        }

                        path.pathType  = AC_PathType.ForwardOnly;
                        path.pathSpeed = speed;
                        path.affectY   = true;

                        Vector3[] pointArray;
                        Vector3   targetPosition = marker.transform.position;

                        if (KickStarter.settingsManager.ActInScreenSpace())
                        {
                            targetPosition = AdvGame.GetScreenNavMesh(targetPosition);
                        }

                        if (pathFind && KickStarter.navigationManager)
                        {
                            pointArray = KickStarter.navigationManager.navigationEngine.GetPointsArray(charToMove, charToMove.transform.position, targetPosition);
                        }
                        else
                        {
                            List <Vector3> pointList = new List <Vector3>();
                            pointList.Add(targetPosition);
                            pointArray = pointList.ToArray();
                        }

                        if (speed == PathSpeed.Walk)
                        {
                            charToMove.MoveAlongPoints(pointArray, false);
                        }
                        else
                        {
                            charToMove.MoveAlongPoints(pointArray, true);
                        }

                        if (charToMove.activePath)
                        {
                            if (!pathFind && doFloat)
                            {
                                charToMove.activePath.affectY = true;
                            }
                            else
                            {
                                charToMove.activePath.affectY = false;
                            }
                        }

                        if (willWait)
                        {
                            return(defaultPauseTime);
                        }
                    }
                }

                return(0f);
            }
            else
            {
                if (!charToMove.IsPathfinding())
                {
                    isRunning = false;
                    return(0f);
                }
                else
                {
                    return(defaultPauseTime);
                }
            }
        }