collision glitch

im having a glitch where when i touch something it pushs me, but only when i hit a certian side, heres the clip link
obqp7d
after i jump and hit the block im not touching anything but my mouse to turn my camera
if theres any way to fix this plese let me know

Just looks like you’re using no friction?

@ ya,had i this problem and no friction fixed it but it cme back

@ i changed my friction to 1000 it did nothing jep0c4

How are you moving your character? Could you share the script you’re using?

@arkano22 ya heres my code

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

public class PlayerMovement : MonoBehaviour
{

    public float speed = 5.0f;
    public float jumpForce = 5.0f;
    public bool isOnGround = true;
    private float horizontalInput;
    private float forwardInput;
    private Rigidbody playerRb;

    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        // get player input
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");

        //Move player forward
        Vector3 movement = new Vector3(horizontalInput, 0.0f, forwardInput) * speed * Time.deltaTime;
        playerRb.MovePosition(transform.position + transform.TransformDirection(movement));

        // let player jump
        if (Input.GetKeyDown(KeyCode.Space) & isOnGround)
        {
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            isOnGround = false;
        }

    }
    private void OnCollisionEnter(Collision collision)
    {
         

        if (collision.gameObject.CompareTag("Ground"))
        {
            isOnGround = true;
        }
    }
   
}

You should not be using MovePosition on a 3D Dynamic body. it’s meant for Kinematic bodies. In 3D when you use it, it simply (instantly) teleports to that position.

You should also only perform a MovePosition in FixedUpdate as that’s when physics (by default) runs. Another minor note but when referring to the position of the body (or rotation) you should directly use the Rigidbody positon/rotation and not the Transform. The Transform is for visuals and other components, it won’t be at the pose of the Rigidbody if you’re using Interpolation or Extrapolation.

I’d deal with these first before further investigation.

@MelvMay I used a different movement tutorial and it fixed the physics problem but now this is happening
azv0j0

heres my code now

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

public class PlayerMovement : MonoBehaviour
{
   
    public float walkSpeed = 6f;
    public float runSpeed = 12f;
    public float jumpPower = 7f;
    public float gravity = 10f;
    public float defaultHeight = 2f;
   

    private Vector3 moveDirection = Vector3.zero;
    private CharacterController characterController;

    private bool canMove = true;

    void Start()
    {
        characterController = GetComponent<CharacterController>();
       
    }

    void Update()
    {
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 right = transform.TransformDirection(Vector3.right);

        bool isRunning = Input.GetKey(KeyCode.LeftShift);
        float curSpeedX = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis("Vertical") : 0;
        float curSpeedY = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis("Horizontal") : 0;
        float movementDirectionY = moveDirection.y;
        moveDirection = (forward * curSpeedX) + (right * curSpeedY);

        if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
        {
            moveDirection.y = jumpPower;
        }
        else
        {
            moveDirection.y = movementDirectionY;
        }

        if (!characterController.isGrounded)
        {
            moveDirection.y -= gravity * Time.deltaTime;
        }

      
       
        characterController.Move(moveDirection * Time.deltaTime);

       
    }
  
   
}

What is happening? Remember, you’re close to your project and unexpected things but it’s not immediately clear to others. Please describe problems.

Thanks.

** @MelvMay My fault i used the wrong vid my cameras Y position is randomly going up and downqov8w1**

what do i do?

How could I possibly answer that? You have the project, you can debug what’s going on and you can provide that information here so maybe someone can suggest further things to try. There’s no magic knowledge here without information. :wink:

im new to this sorry, how would i troubleshoot?

Hard to just tell you how to debug, it’s a skill you have to learn either from tutorials or reading about it online.

The main thing is to verify that what you expect to be happening, is happening. You can do this by attaching a debugger and stepping through the code or depending on what you’re checking, just add “Debug.Log(xxx)” calls and look at the console to see if it’s what you expect.

The logic you have, you expect X to happen then it to do Y and/or Z. You need to verify that this is happening.

Ty ill try tht