Ejemplo n.º 1
0
        private void HazardHandler(Vector2 hazardRay)
        {
            if (_controller.MovementState.ApproachingSnow)
            {
                _animator.SetTrigger(DenizenAnimBool.AtSnow);
            }
            else if ((_controller.MovementState.RightCollision && DirectionTravelling == DirectionTravelling.Right) ||
                     (_controller.MovementState.LeftCollision && DirectionTravelling == DirectionTravelling.Left))
            {
                _animator.SetTrigger(DenizenAnimBool.AtWall);
            }
            else if (ApproachingEdge())
            {
                _animator.SetTrigger(DenizenAnimBool.AtEdge);
            }
            else
            {
                return;
            }

            if (CanMove)
            {
                DirectionTravelling = DirectionTravelling.None;
                _transitioning      = true;
            }
        }
Ejemplo n.º 2
0
 public void SetTravelInDirectionFacing()
 {
     if (CanMove)
     {
         DirectionTravelling = GetDirectionFacing() == DirectionFacing.Right
                                 ? DirectionTravelling.Right
                                 : DirectionTravelling.Left;
     }
 }
Ejemplo n.º 3
0
 private void CheckStopMoving()
 {
     if (_animator.GetBool(DenizenAnimBool.InSnow) ||
         _animator.GetBool(DenizenAnimBool.PlayerSpotted) ||
         _animator.GetBool(DenizenAnimBool.SatAtFireplace)
         )
     {
         DirectionTravelling = DirectionTravelling.None;
     }
 }
Ejemplo n.º 4
0
        public void MovePivotAlongSurface(DirectionTravelling direction, float distance)
        {
            Vector3 v = OrientationHelper.GetSurfaceVectorTowardsRight(Pivot.transform);

            if (direction == DirectionTravelling.Left)
            {
                v = -v;
            }

            Vector3 movement = v.normalized * distance;

            UpdatePivot = false;
            Pivot.transform.Translate(movement, Space.World);
        }
Ejemplo n.º 5
0
        void OnTriggerEnter2D(Collider2D col)
        {
            if (_isSliding == false && col.gameObject.layer == LayerMask.NameToLayer(Layers.Flash) && _controller.CanSeeFlash(col.transform.position))
            {
                _isFlashed          = true;
                DirectionTravelling = DirectionTravelling.None;

                bool isFacingRight = GetDirectionFacing() == DirectionFacing.Right;
                bool isPlRight     = col.transform.position.x >= transform.position.x;

                if (isFacingRight == isPlRight)
                {
                    FlipSprite();
                }

                _animator.Play(Animator.StringToHash(Animations.Flash));
            }
        }
Ejemplo n.º 6
0
        private void DetermineMovement()
        {
            if (_controller.MovementState.IsGrounded)
            {
                _velocity.y = 0;

                if (_atStove)
                {
                    DirectionTravelling = DirectionTravelling.None;
                    _animator.SetTrigger(DenizenAnimBool.LightStove);
                    _transitioning = true;
                }
                else if (DirectionTravelling == DirectionTravelling.Right)
                {
                    _normalizedHorizontalSpeed = 1;
                    if (GetDirectionFacing() == DirectionFacing.Left)
                    {
                        FlipSprite();
                    }
                    HazardRight();
                }
                else if (DirectionTravelling == DirectionTravelling.Left)
                {
                    _normalizedHorizontalSpeed = -1;
                    if (GetDirectionFacing() == DirectionFacing.Right)
                    {
                        FlipSprite();
                    }
                    HazardLeft();
                }
                else
                {
                    _normalizedHorizontalSpeed = 0;
                    if (_transitioning == false)
                    {
                        HazardLeft();
                        HazardRight();
                    }
                }
            }

            _atStove = false;
        }
Ejemplo n.º 7
0
        private bool ApproachingEdge()
        {
            if (DirectionTravelling == DirectionTravelling.None ||
                (_controller.MovementState.RightEdge == false && _controller.MovementState.LeftEdge == false) ||
                (_controller.MovementState.RightEdge && DirectionTravelling == DirectionTravelling.Left) ||
                (_controller.MovementState.LeftEdge && DirectionTravelling == DirectionTravelling.Right))
            {
                return(false);
            }

            if (CanJump == false)
            {
                return(true);
            }

            const float checkLength = 6f;
            const float checkDepth  = 4f;

            var origin = new Vector2(
                _controller.Collider.bounds.center.x,
                _controller.Collider.bounds.min.y);

            var size = new Vector2(0.01f, checkDepth);

            Vector2   castDirection = GetDirectionFacing() == DirectionFacing.Left ? Vector2.left : Vector2.right;
            LayerMask mask          = GetDirectionFacing() == DirectionFacing.Left
                ? 1 << LayerMask.NameToLayer(Layers.RightClimbSpot)
                : 1 << LayerMask.NameToLayer(Layers.LeftClimbSpot);

            RaycastHit2D hit = Physics2D.BoxCast(origin, size, 0, castDirection, checkLength, mask);

            if (hit)
            {
                DirectionTravelling = DirectionTravelling.None;
                _isJumping          = true;
                _controller.MovementState.SetPivotCollider(hit.collider, ColliderPoint.TopFace, ColliderPoint.BottomFace);
                _animator.SetTrigger(DenizenAnimBool.Jump);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        private bool AtEdge(Bounds bounds, DirectionTravelling direction)
        {
            if (_motor.MovementState.IsOnSlope || _downHit.transform.gameObject.layer == LayerMask.NameToLayer(Layers.Ice))
            {
                return(false);
            }

            float xOrigin = direction == DirectionTravelling.Right
                ? bounds.max.x + 0.1f
                : bounds.min.x - 0.1f;
            var edgeRay = new Vector2(xOrigin, bounds.min.y);

            Debug.DrawRay(edgeRay, _motor.MovementState.GetSurfaceDownDirection(), Color.blue);
            RaycastHit2D hit    = Physics2D.Raycast(edgeRay, _motor.MovementState.GetSurfaceDownDirection(), 1.5f, Layers.Platforms);
            bool         atEdge = hit == false ? true : Vector2.Angle(Vector2.up, hit.normal) > _motor.SlopeLimit;

            if (atEdge)
            {
                edgeRay += new Vector2(direction == DirectionTravelling.Right ? 1 : -1, ConstantVariables.MaxLipHeight);
                RaycastHit2D hit2 = Physics2D.Raycast(edgeRay, Vector2.down, 1.5f + ConstantVariables.MaxLipHeight, Layers.Platforms);
                atEdge = hit2 == false ? true : Vector2.Angle(Vector2.up, hit2.normal) > _motor.SlopeLimit;
            }

            if (atEdge)
            {
                if (direction == DirectionTravelling.Right)
                {
                    _motor.MovementState.OnRightEdge();
                }
                else
                {
                    _motor.MovementState.OnLeftEdge();
                }
            }

            return(atEdge);
        }
Ejemplo n.º 9
0
 public Vector3 GetSurfaceDirection(DirectionTravelling direction)
 {
     return(direction == DirectionTravelling.Right
                         ? Quaternion.Euler(0, 0, -90) * Normal
                         : Quaternion.Euler(0, 0, 90) * Normal);
 }
Ejemplo n.º 10
0
        private bool DirectionCast(Bounds bounds, DirectionTravelling direction, bool offGround)
        {
            Vector2      dir = direction == DirectionTravelling.Left ? Vector2.left : Vector2.right;
            RaycastHit2D hit = GetDirectionHit(bounds, dir);

            if (hit)
            {
                if (hit.collider.gameObject.layer == LayerMask.NameToLayer(Layers.Ice))
                {
                    _motor.MovementState.ApproachingSnow = true;
                }

                float lipHeight = bounds.min.y + ConstantVariables.MaxLipHeight;
                if (offGround || hit.point.y > lipHeight)
                {
                    if (direction == DirectionTravelling.Left)
                    {
                        _motor.MovementState.OnLeftCollision();
                    }
                    else
                    {
                        _motor.MovementState.OnRightCollision();
                    }
                    return(hit);
                }

                if (direction == DirectionTravelling.Left)
                {
                    //special player crouch check/set
                    RaycastHit2D lipHit = Physics2D.Raycast(new Vector2(bounds.min.x - 0.3f, bounds.max.y), Vector2.down, bounds.size.y, Layers.Platforms);
                    if (ActualSidewaysCollision(lipHit, lipHeight))
                    {
                        _motor.MovementState.OnLeftCollision();
                    }
                    else
                    {
                        hit     = new RaycastHit2D();
                        _lipHit = lipHit;
                    }
                }
                else
                {
                    RaycastHit2D lipHit = Physics2D.Raycast(new Vector2(bounds.max.x + 0.3f, bounds.max.y), Vector2.down, bounds.size.y, Layers.Platforms);
                    if (ActualSidewaysCollision(lipHit, lipHeight))
                    {
                        _motor.MovementState.OnRightCollision();
                    }
                    else
                    {
                        hit     = new RaycastHit2D();
                        _lipHit = lipHit;
                    }
                }
            }
            if (offGround)
            {
                return(false);
            }
            else
            {
                return(hit || AtEdge(bounds, direction));
            }
        }
Ejemplo n.º 11
0
        void Update()
        {
            _isSliding = _controller.MovementState.IsOnSlope && _controller.MovementState.TrappedBetweenSlopes == false;
            _animator.SetBool(DenizenAnimBool.Sliding, _isSliding);
            _wasSliding = _isSliding && _wasSliding;
            if (_isSliding && _wasSliding == false && _animator.GetBool(DenizenAnimBool.Falling) == false)
            {
                _animator.Play(Animator.StringToHash(Animations.BeginSlide));
                _wasSliding = true;
            }

            _animator.SetBool(DenizenAnimBool.InSnow, _controller.MovementState.OnSnow);
            if (_isSliding == false &&
                _animator.GetBool(DenizenAnimBool.InSnow) == false &&
                _isFlashed == false)
            {
                bool playerSpotted = SpotPlayer();
                if (playerSpotted &&
                    _isJumping == false &&
                    _animator.GetBool(DenizenAnimBool.SatAtFireplace) == false &&
                    _animator.GetBool(DenizenAnimBool.PlayerSpotted) == false)
                {
                    _animator.Play(Animator.StringToHash(Animations.Gasp));
                }
                _animator.SetBool(DenizenAnimBool.PlayerSpotted, playerSpotted);
            }
            _animator.SetBool(DenizenAnimBool.SatAtFireplace, _controller.SatAtFireplace);

            CheckStopMoving();

            if (_isSliding)
            {
                if (_controller.MovementState.NormalDirection == DirectionFacing.Right)
                {
                    if (GetDirectionFacing() == DirectionFacing.Left)
                    {
                        FlipSprite();
                    }
                    _normalizedHorizontalSpeed = 1;
                    DirectionTravelling        = DirectionTravelling.Right;
                }
                else
                {
                    if (GetDirectionFacing() == DirectionFacing.Right)
                    {
                        FlipSprite();
                    }
                    _normalizedHorizontalSpeed = -1;
                    DirectionTravelling        = DirectionTravelling.Left;
                }
                MoveWithVelocity();
            }
            else if (_isJumping)
            {
                JumpAcross();
            }
            else
            {
                if (_controller.SatAtFireplace || CanMove == false)
                {
                    DirectionTravelling = DirectionTravelling.None;
                }

                _animator.SetBool(DenizenAnimBool.Moving, DirectionTravelling != DirectionTravelling.None);
                DetermineMovement();
                if (_isJumping == false)
                {
                    MoveWithVelocity();
                }
            }
            SetVelocity();
        }
Ejemplo n.º 12
0
 void MoveToFireplace(DirectionTravelling direction)
 {
     DirectionTravelling = direction;
     _animator.SetTrigger(DenizenAnimBool.MoveToFireplace);
 }
Ejemplo n.º 13
0
 private void SendRaycastMessage(RaycastHit2D hit, DirectionTravelling direction)
 {
     hit.collider.SendMessage("MoveToFireplace", direction, SendMessageOptions.DontRequireReceiver);
 }