Rigidbody clips through corners ignoring collision

hi everyone, I’ ve run into a problem.
The collisions with my player work perfectly on everything except for when the player collides with an angle; in that case it clips through; I wanted to know a solution to this problem cause I can’t find any answer on this topic on the forum.

here’s the code of my player obj:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

    public float mouseSensitivityX = 1.0f;
    public float mouseSensitivityY = 1.0f;
    public float walkSpeed = 10.0f;
    Vector3 moveAmount;
    Vector3 smoothMoveVelocity;

    public Transform cameraT;
    float verticalLookRotation;

    public Rigidbody rigidbodyR;

    float jumpForce = 250.0f;
    bool grounded;
    public LayerMask groundedMask;

    // Use this for initialization
    void Start ()
    {
        Cursor.visible = false;
        rigidbodyR = GetComponent<Rigidbody> ();
       
    }
   
    // Update is called once per frame
    void Update () {
        Cursor.lockState = CursorLockMode.Locked;
        // rotation
        transform.Rotate (Vector3.up * Input.GetAxis ("Mouse X") * mouseSensitivityX);
        verticalLookRotation += Input.GetAxis ("Mouse Y") * mouseSensitivityY;
        verticalLookRotation = Mathf.Clamp (verticalLookRotation, -60, 60);
        cameraT.localEulerAngles = Vector3.left * verticalLookRotation;

        // movement
        if (!Input.GetButton("Fire2"))  
       {
          Vector3 moveDir = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")).normalized;
          Vector3 targetMoveAmount = moveDir * walkSpeed;
          moveAmount = Vector3.SmoothDamp (moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
       }
       else if (Input.GetButton("Fire2"))
       {
          Vector3 moveDir = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")).normalized;
          Vector3 targetMoveAmount = moveDir * walkSpeed * 0f;
          moveAmount = Vector3.SmoothDamp (moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
       }
         
          // jump
          if (Input.GetButtonDown ("Jump")) {
            if (grounded) {
                rigidbodyR.AddForce (transform.up * jumpForce);
            }
          }

          Ray ray = new Ray (transform.position, -transform.up);
          RaycastHit hit;

          if (Physics.Raycast(ray, out hit, 1 + .1f, groundedMask)) {
            grounded = true;
          }
          else {
            grounded = false;
          }
      
    }

    void FixedUpdate() {
        rigidbodyR.MovePosition (rigidbodyR.position + transform.TransformDirection (moveAmount) * Time.fixedDeltaTime);
    }
   
}

thank you in advance:):stuck_out_tongue:

You do know that pasting a bunch of code does not demonstrate a problem right? This description could mean anything.

Because this isn’t a “topic”.

All I can say is that you’re performing explicit moves using move-position and adding forces. Those two are opposing things. You either want explict motion or you want to use forces; not both. No idea if this relates to your “problem”.