Exemplo n.º 1
0
    // TRIGGER COLLISION
    void OnTriggerStay2D(Collider2D other)
    {
        // While inside an "Stay" call, this full statement should only go through once
        // per initial climb.
        if (!climbing)
        {
            if (other.tag == "Climbable" &&
                Input.GetAxis("Vertical") != 0 &&
                !isJumpingOff)
            {
                climbing       = true;
                rb.velocity    = Vector2.zero;
                climbingCenter = other.transform.position.x;

                ClimbableObject climbableObject = other.gameObject.GetComponent <ClimbableObject>();

                // Checks if climbable Surface allows pass-through, disables ground collision if so
                if (climbableObject.allowPassthrough)
                {
                    Physics2D.IgnoreLayerCollision(playerLayer, envrionmentLayer, true);
                    passingThrough = true;
                }
            }
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Can the ability be started?
 /// </summary>
 /// <returns>True if the ability can be started.</returns>
 public override bool CanStartAbility()
 {
     // The character can climb if the character is on the ground and a climbable object is near.
     if (m_Controller.Grounded &&
         Physics.SphereCast(m_Transform.position + m_Transform.up * 0.1f - m_Transform.forward * m_SearchRadius, m_SearchRadius, m_Transform.forward, out m_RaycastHit, m_StartClimbMaxDistance + m_SearchRadius, m_ClimbableLayer.value, QueryTriggerInteraction.Ignore))
     {
         // The character must be mostly looking at the climbable object.
         if (Vector3.Angle(-m_RaycastHit.normal, m_Transform.forward) < m_StartClimbMaxAngle)
         {
             if ((m_ClimbableObject = Utility.GetComponentForType <ClimbableObject>((m_ClimbableTransform = m_RaycastHit.transform).gameObject)) != null)
             {
                 m_ClimbableObject.Mount(m_Transform);
                 if (Utility.GetComponentForType <BoxCollider>(m_ClimbableObject.gameObject) != null)
                 {
                     m_StartNormal        = m_ClimbableTransform.forward * (Mathf.Sign(m_ClimbableTransform.InverseTransformPoint(m_Transform.position).z) == -1 ? 1 : -1);
                     m_ClimbNormal        = m_ClimbableTransform.forward * (m_ClimbableObject.CanReverseMount && Mathf.Sign(m_ClimbableTransform.InverseTransformPoint(m_Transform.position).z) == -1 ? 1 : -1);
                     m_MountStartPosition = m_ClimbableObject.MountPosition(false);
                 }
                 else
                 {
                     m_ClimbNormal   = m_StartNormal = -m_RaycastHit.normal;
                     m_StartNormal.y = 0;
                     m_StartNormal.Normalize();
                     // If there is no BoxCollider then the start position is based off of the raycast hit position.
                     m_MountStartPosition = m_RaycastHit.point + Quaternion.LookRotation(-m_StartNormal) * m_ClimbableObject.MountPosition(true);
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
    void OnTriggerExit2D(Collider2D other)
    {
        // When leaving a climbable object
        if (other.tag == "Climbable")
        {
            climbing = false;

            ClimbableObject climbableObject = other.gameObject.GetComponent <ClimbableObject>();

            // Ensures player collides with geometry again after jumping off or leaving
            // a climbable object with pass-through enabled
            if (climbableObject.allowPassthrough)
            {
                Physics2D.IgnoreLayerCollision(playerLayer, envrionmentLayer, false);
                passingThrough = false;
            }
        }
    }
Exemplo n.º 4
0
 internal void StopClimbing()
 {
     _climbing       = false;
     _climbingObject = null;
 }
Exemplo n.º 5
0
 internal void ClimbZoneEntered(Collider2D collision)
 {
     _climbingObject = collision.GetComponentInChildren <ClimbableObject>();
 }