Untitled

 avatar
unknown
csharp
3 years ago
1.9 kB
4
Indexable
//This is the code what is used for ground checking atm. Allows player to move and OnGround = false all the time in fixedUpdate;

private void OnCollisionStay(Collision other) {

        
        if(other.transform.tag == "Surf" && !isSurfing)
        {
            isSurfing = true;
        }

        // Check if any of the contacts has acceptable floor angle
        //(contact.normal.y > Mathf.Sin(slopeLimit * (Mathf.PI / 180f) + Mathf.PI/2f))
        //if (contact.normal.y > 0 && contact.normal.x <= 0 && contact.normal.z <= 0)
        
        foreach (ContactPoint contact in other.contacts) {
            {
                if (contact.normal.y > Mathf.Sin(slopeLimit * (Mathf.PI / 180f) + Mathf.PI / 2f))
                {
                    groundNormal = contact.normal;
                    onGround = true;
                    jumpCounter = 1;
                    return;
                }
            }
        }
        
    }
    
    // This was raycast method to set onGround = rayGround in fixedUpdate. It didin't allow player move anymore.
    
      bool rayGround
    {
  

        get
        {
            Vector3 vecDown = transform.TransformDirection(Vector3.down);
            bool result = false;

            result |= Physics.Raycast(transform.position + new Vector3(0, 0.2f, 0), vecDown, 0.6f, groundMask);
            result |= Physics.Raycast(transform.position + new Vector3(-0.2f, 0.2f, 0), vecDown, 0.6f, groundMask);
            result |= Physics.Raycast(transform.position + new Vector3(0.2f, 0.2f, 0), vecDown, 0.6f, groundMask);
            result |= Physics.Raycast(transform.position + new Vector3(0, 0.2f, 0.2f), vecDown, 0.6f, groundMask);
            result |= Physics.Raycast(transform.position + new Vector3(0, 0.2f, -0.2f), vecDown, 0.6f, groundMask);

            return result;
        }
    }
Editor is loading...