How do i freeze position and use collision?

I have this player with a sphere collider but when i run into a wall it pushes me to the side when i keep running due to my collider shape and i don’t want this to happen, but when i enable freeze x and z position on RB the player can pass through walls how can i get this to test and stop for collision and not be moved by it.

Could you post your moving code?

float playerRotation = Input.GetAxis ("Mouse X");
        float moveVertical = Input.GetAxis ("Vertical");
        float moveHorizontal = Input.GetAxis ("Horizontal");

            transform.Translate (moveHorizontal * speed * Time.deltaTime, 0, moveVertical * speed * Time.deltaTime);
            transform.Rotate(0, playerRotation * rotationSpeed, 0);
        if (Input.GetKey (KeyCode.Space) && grounded == true) {
            jumpPos = 0.3f;
        }
        transform.Translate(new Vector3(0,0 + jumpPos,0));
    if(jumpPos > 0.01f)
        jumpPos -= 0.01f;

    }

Yeah,that’s it, never ever use transform. Translate, it ignores collision, use rigidbody instead

but the only movement i know with rigidbody is rigidbody.AddForce() but i want the movement to respond instantly to have smooth movement, rigidbodys movement adds up force until its high enough then moves it quickly and then you have to apply lots of force then to stop it, so i don’t like using rigidbodys movement.

If you dont want realistic physics, then change the velocity itself, it will be instant, and you can make it stop instantly too.

What is the code to do that?

If you have the rigidbody already as a variqble, tgen rb.velocity =, where rb is tge variable

this: RB.velocity = new Vector3(moveHorizontal * speed, 0, moveVertical * speed); doesn’t work it move the player along the global vector not local. this doesn’t work efficiently with my method of movement.

Multiple everything them with transform.forwards corresponding axis, so tranform.forward.x, or.y and for y value use rb.velocity.y

What do you mean?

Rb.velocity = Vector3(put your movement here) * transform.forward

When i try that it gives me errors.

error CS0019: Operator *' cannot be applied to operands of type UnityEngine.Vector3’ and `UnityEngine.Vector3’

just look at this, it will help-

This shows how to rotate player not move it.

Continue that tutorial series, its good