Custom movement problem

I’m creating a movement system from scratch, using transform.Tranlate, since I didn’t like using character controller and want constant movement speed.

void Update () {
		if(Physics.Raycast(transform.position, -transform.up,1f)) _grounded = true;
		else _grounded = false;
	if(_grounded )
		if (Input.GetKeyDown(KeyCode.Space))
            rigidbody.AddRelativeForce(transform.up * 7, ForceMode.Impulse);
		rigidbody.AddRelativeForce(transform.up * -20, ForceMode.Force);
	if(!Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.W)) transform.Translate(0, 0, 1);
	if(!Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.S)) transform.Translate(0, 0, -1);
	if(Input.GetKey(KeyCode.D) ) transform.Translate(1, 0, 0);
	if(Input.GetKey(KeyCode.A)) transform.Translate(-1, 0, 0);

The problem is that my capsule seems to move on its own, especially after running towards a wall or other element with a collider. It’s even worse since this movement cannot be stopped - sometimes it stops itself after a while.

Capsule has capsule collider and rigidbody attached (Doesn’t use gravity, since the script does it). I found the solution to the stange movement problem by freezing position x an z in rigidbody (y is needed for force jumps). This solves the strange movements but now my capsule doesn’t collide when I’m walking into something like cubes.

I feel like I’m running in circles here trying to fix another bug caused by the bug before, so I’m asking you guys - is there a simple solution to those problems? I’d rather not go back to using the character controller because this way it’s easier for me to add new functions like sprinting or sneaking, and I’m not a unity or C# pro.

The problem is (as usual with these things) that you are using a ‘transform.translate’ style controller, at the same time as using a rigidbody. A rigidbody object will always try to use Unity’s inbuilt phyisics engine- so you should either write your entire movement script around that, or get rid of it entirely. Since you seem to be using it for jumps only, try writing the ‘gravity’ physics manually- keep track of its velocity, and apply gravity when it is above the ground.

Another thing- your input matrix looks really weird. Why don’t you use Input.GetAxis instead?