Exemplo n.º 1
0
 public void StartClimbing(ObstacleSize obstacleSize)
 {
     Animator.ResetTrigger("JumpStart");
     Animator.SetFloat("ObstacleHeight", (float)obstacleSize);
     Animator.SetBool("IsClimbing", true);
     Animator.SetTrigger("Climb");
 }
    private void ClimbOverObstacle(ObstacleSize obstacleSize, Vector2 obstacleApproxPosition, GameObject obstacleObject)
    {
        //Debug.Log($"Climb over obstacle {obstacleSize} ({obstacleObject.name}). grounded: {m_Grounded}, climbing: {m_Climbing}, haswalljumped: {_hasWallJumped}, interrupt: {_interruptClimbToJump}");
        _obstacleCurrentlyClimbing = obstacleObject;

        if ((obstacleSize == ObstacleSize.Above6 && m_Grounded) ||
            (obstacleSize >= ObstacleSize.Above3 && !m_Grounded))
        {
            // if obstacle is too high, we can't go on top of it but we still try to climb it
            m_Climbing = true;
            // animate to this location
            m_Rigidbody2D.velocity = Vector2.zero;
            var targetPosition = new Vector2(transform.position.x, transform.position.y + (m_Grounded ? MaxClimbDistanceIfObstacleIsTooHigh : MaxClimbDistanceAfterJumpIfObstacleIsTooHigh));
            StartCoroutine(MoveToTargetPosition(targetPosition));
            GetComponent <AudioSource>().PlayOneShot(ClimbSfx);
            OnClimbStartEvent.Invoke(obstacleSize);
        }
        else
        {
            // identify where to land on the obstacle
            var hit = Physics2D.Raycast(obstacleApproxPosition + Vector2.up * 2, Vector3.down, 5, m_WhatIsGround);
            Debug.DrawRay(obstacleApproxPosition + Vector2.up * 2, Vector3.down * 5, Color.white, 2f);
            if (hit.collider != null)
            {
                Debug.DrawLine(new Vector3(hit.point.x - 1, hit.point.y, 1), new Vector3(hit.point.x + 1, hit.point.y, 1), Color.red, 2f);
                Debug.DrawLine(new Vector3(hit.point.x, hit.point.y - 1, 1), new Vector3(hit.point.x, hit.point.y + 1, 1), Color.red, 2f);

                //Debug.Log("position to reach : " + hit.point);
                m_Climbing = true;
                // animate to this location
                m_Rigidbody2D.velocity = Vector2.zero;
                StartCoroutine(MoveToTargetPosition(hit.point));
                GetComponent <AudioSource>().PlayOneShot(ClimbSfx);
                OnClimbStartEvent.Invoke(obstacleSize);
            }
        }

        m_Grounded = false;
    }