private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();
        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMovement.x < 0 && wasGrounded)
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > 0.001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);
            CorrectHorizontalPlacament(ref deltaMovement, true);
            CorrectHorizontalPlacament(ref deltaMovement, false);
        }
        _transform.Translate(deltaMovement, Space.World);
        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / (Time.deltaTime);
        }

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);
            if (_lastStandingOn != StandingOn)
            {
                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
        }
    }
Ejemplo n.º 2
0
    private void Move(Vector2 deltaMove)
    {
        bool wasGrounded = State.IsCollidingDown;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMove.y < 0 && wasGrounded)
            {
                HandleSlopeVertical(ref deltaMove);
            }

            float leftDist  = HorizontalCollision(ref deltaMove, -1);
            float rightDist = HorizontalCollision(ref deltaMove, 1);

            //if(Mathf.Abs(deltaMove.x) > 0.001f){
            //	MoveHorizontally(ref deltaMove, (Mathf.Sign(deltaMove.x) == 1) ? rightDist : leftDist, 0f);
            //}
            //MoveHorizontally(ref deltaMove);

            MoveVertically(ref deltaMove);
            //CorrectHorizontalPlacement(ref deltaMove, true);
            //CorrectHorizontalPlacement(ref deltaMove, false);
        }

        _transform.Translate(deltaMove, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMove / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(_transform.position);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
        }
    }
Ejemplo n.º 3
0
    }     // end LateUpdate

    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();             // handles moving platforms
            CalculateRayOrigins();

            if (deltaMovement.y < 0 && wasGrounded)             // if they're moving down, e.g. affected by gravity and on a vertical slope
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > .001f)              // horizontal slope handled
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);              // always a vertical force applying, namely gravity

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        _transform.Translate(deltaMovement, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            /*Debug.DrawLine(transform.position, _activeGlobalPlatformPoint);
             * Debug.DrawLine(transform.position, _activeLocalPlatformPoint);*/

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);                     // ensures that not all objects on which player might possibly stand listen to all 3 events
                }
                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }     // end Move
    private void Move(Vector2 deltaMovement)
    {
        //Debug.Log ("Velocity: " + deltaMovement);
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMovement.y < 0 && wasGrounded)
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > .001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        // Fall Death Script
        if (State.IsCollidingBelow == true)
        {
            // do nothing
        }
        else
        {
            if (FallVelocity.y > deltaMovement.y)
            {
                Debug.Log("Velocity: " + FallVelocity);
                FallVelocity = deltaMovement;
                Debug.Log("Velocity2: " + FallVelocity);
            }
        }

        if (FallVelocity.y <= -2.0 && State.IsCollidingBelow == true && !dead)
        {
            LevelManager.Instance.KillPlayer();
        }
        else if (State.IsCollidingBelow == true)
        {
            FallVelocity = deltaMovement;
        }



        _transform.Translate(deltaMovement, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
    /// <summary>
    /// Движение персонажа
    /// </summary>
    /// <param name="deltaMovement">Шаг передвижения</param>
    private void Move(Vector2 deltaMovement)
    {
        // получаем статус или был игрок на земле
        var wasGrounded = State.IsColidingBelow;

        // сбрасываем статус
        State.Reset();

        // Проверка столкновений в awake устанавливаем true
        // В данном цикле мы изменяем в соответствии до направления движения переменную ref deltaMovement
        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            // Если персонаж движется вниз по у и был на земле
            // Тогда его передвижения - движение по склонной поверхности
            if (deltaMovement.y < 0 && wasGrounded)
            {
                // ref потому что в логике метода нужно будет изменить расстояние - deltaMovement
                HandleVerticalSlope(ref deltaMovement);
            }

            // Если передвижение хоть минимальное тогда есть смысл двигать персонажа
            if (Mathf.Abs(deltaMovement.x) > .001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            // Движение по вертикали выполнять всегда потому что есть гравитация и оно может постоянно меняться
            MoveVertically(ref deltaMovement);

            // Пускаем лучи внутри игрока (до кожи) для проверки или ничто в него не зашло
            // и изменяем его позицию если что то действует на него
            // вправо
            CorrectHorizontalPlacement(ref deltaMovement, true);
            // влево
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        // После цикла получая измененную переменную  передвигаем персонажа
        _transform.Translate(deltaMovement, Space.World);

        // ?? Задаем новую скорость которая зависит от времени перемещения
        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        // Возвращаем меньшее из 2 чисел - скорость что мы рассчитали
        // и MAxVelocity.x,y - которые задаем в игре в скрипте
        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        //,,,,,,,,,,,,,,,,,
        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        // Если стоим на платформе
        if (StandingOn != null)
        {
            // глобальная позиция платформы = позиции игрока
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
    /// <summary>
    /// Metoda odpowiedzialna za obsluge ruchu.
    /// </summary>
    private void Move(Vector2 deltaMovement)
    {
        /// Zapamietujemy czy gracz znajduje sie na podlozu, a
        /// nastepnie resetujemy stan.
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            /// Ruch w pionie to tez ruch spowodowany grawitacja, nastepnie sprawdzamy czy
            /// jestesmy na ziemi i sprawdzamy czy nalezy obsluzyc pionowy aspekt
            /// ruchu po pochylej powierzchni.
            if (deltaMovement.y < 0 && wasGrounded)
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            /// Jesli wykryto ruch w lewo lub prawo,
            /// obslugiwany jest ruch w poziomie.
            if (Mathf.Abs(deltaMovement.x) > .001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            /// Ruch w pionie obslugiwany jest zawsze ze wzgledu na grawitacje.
            MoveVertically(ref deltaMovement);

            /// Wywolywana metoda obslugujaca zderzenia z platfroma
            /// w poziomie, dla sytuacji gdy gracz porusza sie
            /// w prawo lub w lewo.
            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        /// Wartosc wykonanego ruchu jest przekazywana do Unity.
        _transform.Translate(deltaMovement, Space.World);

        /// Predkosc aktualizowana jest o uplyw czasu w grze.
        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        /// Ograniczenie wartosci predkosci do obecnej lub
        /// ustalonej jako maksymalna.
        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        /// Jesli poruszamy sie w gore po pochylej powierzchni,
        /// predkosc w pionie przyjmuje wartosc 0.
        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        /// Jesli gracz stoi na jakims obiekcie.
        if (StandingOn != null)
        {
            /// Pozycja gracza.
            _activeGlobalPlatformPoint = transform.position;
            /// Pozycja gracza w relacji do platformy, na ktorej stoi.
            _activeLocalPlatformPoint = StandingOn.transform.InverseTransformPoint(transform.position);

            Debug.DrawLine(transform.position, _activeGlobalPlatformPoint);
            Debug.DrawLine(transform.position, _activeLocalPlatformPoint);

            /// Nie stoimy juz na obiekcie, na ktorym
            /// stalismy w ostatniej klatce animacji gry.
            if (_lastStandingOn != StandingOn)
            {
                /// Jesli istnieje obiekt, na ktorym stalismy w ostaniej klatce,
                /// wysylany jest do niego komunikat o wyjściu.
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                /// Do obiektu, na ktorym obecnie stoimy
                /// wysylany jest komunikat o wejsciu.
                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            /// Jesli istnieje obiekt, na ktorym obecnie stoimy i
            /// stalismy na nim w ostatniej klatce, wysylany jest
            /// do niego komunikat o pozostaniu.
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        /// Jesli gracz obecnie nie stoi na zadnym obiekcie,
        /// ale stal na obiekcie w ostaniej klatce, wysylany jest
        /// do niego komunikat o pozostaniu.
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
Ejemplo n.º 7
0
    private void Move(Vector2 deltaMovement)
    {
        bool wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollision)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            //if (deltaMovement.y < 0 && wasGrounded)
            //	HandleVerticalSlope (ref deltaMovement);

            if (Mathf.Abs(deltaMovement.x) > 0.001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        _transform.Translate(deltaMovement, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        //if (State.IsMovingUpSlope)
        //	_velocity.y = 0;

        if (StandingOn != null)
        {
            //_activeGlobalPlatformPoint = transform.position;
            //_activeLocalPlatformPoint = StandingOn.transform.InverseTransformPoint (transform.position);
            _lastPlatformPosition = StandingOn.transform.position;

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMovement.y < 0 && wasGrounded)
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > .001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        _transform.Translate(deltaMovement, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            // Jumping platform mm... vi kan nu göra scripts till objekt som vi står på gör att vi kan speeda up, bli långsammare etc...
            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
Ejemplo n.º 9
0
    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();                          //moving platforms
            CalculateRaysOrigins();                     //each frame, the rays position depends on the player position

            if (deltaMovement.y < 0 && wasGrounded)     //moving down
            {
                HandleVerticalSlope(ref deltaMovement); //possible modification
            }
            if (Mathf.Abs(deltaMovement.x) > .001f)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }


        _transform.Translate(deltaMovement, Space.World);



        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        //Additional moving platform code

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);//relative position to the platform

            Debug.DrawLine(transform.position, _activeGlobalPlatformPoint);
            Debug.DrawLine(transform.position, _activeLocalPlatformPoint);

            if (_lastStandingOn != StandingOn)
            {//stand on dif object
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            //previously standing on sth
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
Ejemplo n.º 10
0
    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMovement.y < 0 && wasGrounded) // moving down
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > 0.001f) // moving horizontally
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);
        }

        _transform.Translate(deltaMovement, Space.World);

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        // clamp velocity to Max and Min as set in Parameters
        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);

        if (State.IsMovingUpSlope)
        {
            _velocity.y = 0;
        }

        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        } // else if we're not standing on a platform *now*, but we were previously
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
Ejemplo n.º 11
0
    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsGrounded;

        State.Reset();

        if (HandleCollisions)
        {
            HandlePlatforms();
            CalculateRayOrigins();

            if (deltaMovement.y < 0 && wasGrounded)
            {
                HandleVerticalSlope(ref deltaMovement);
            }

            if (Mathf.Abs(deltaMovement.x) > THRESHOLD)
            {
                MoveHorizontally(ref deltaMovement);
            }

            MoveVertically(ref deltaMovement);

            CorrectHorizontalPlacement(ref deltaMovement, true);
            CorrectHorizontalPlacement(ref deltaMovement, false);
        }

        _transform.Translate(deltaMovement, Space.World);

        //TODO: Additional moving platform code

        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }


        // clamping velocities
        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);



        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            Debug.DrawLine(transform.position, _activeGlobalPlatformPoint, Color.white);
            Debug.DrawLine(transform.position, _activeLocalPlatformPoint, Color.blue);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (_lastStandingOn != null)
        {
            _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
            _lastStandingOn = null;
        }
    }
Ejemplo n.º 12
0
    private void Move(Vector2 deltaMovement)
    {
        var wasGrounded = State.IsCollidingBelow;

        State.Reset();

        if (HandleCollisions)
        {
            CalculateRayOrigins();

            MoveVertically(ref deltaMovement);

            if (Mathf.Abs(deltaMovement.x) > 0.001f)
            {
                MoveHorizontally(ref deltaMovement);
            }



            //CorrectHorizontalPlacement(ref deltaMovement, true);
            //CorrectHorizontalPlacement(ref deltaMovement, false);
        }


        _transform.Translate(mapToPlayerOrientation(deltaMovement), Space.World);


        if (Time.deltaTime > 0)
        {
            _velocity = deltaMovement / Time.deltaTime;
        }

        _velocity.x = Mathf.Min(_velocity.x, Parameters.MaxVelocity.x);
        _velocity.y = Mathf.Min(_velocity.y, Parameters.MaxVelocity.y);



        if (StandingOn != null)
        {
            _activeGlobalPlatformPoint = transform.position;
            _activeLocalPlatformPoint  = StandingOn.transform.InverseTransformPoint(transform.position);

            //          Debug.DrawLine(transform.position, _activeGlobalPlatformPoint);
            //          Debug.DrawLine(transform.position, _activeLocalPlatformPoint);

            if (_lastStandingOn != StandingOn)
            {
                if (_lastStandingOn != null)
                {
                    _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                }

                StandingOn.SendMessage("ControllerEnter2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = StandingOn;
            }
            else if (StandingOn != null)
            {
                StandingOn.SendMessage("ControllerStay2D", this, SendMessageOptions.DontRequireReceiver);
            }
            else if (_lastStandingOn != null)
            {
                _lastStandingOn.SendMessage("ControllerExit2D", this, SendMessageOptions.DontRequireReceiver);
                _lastStandingOn = null;
            }
        }
    }