Custom Movement Script lets me walk through walls

I made my own movement script for a top down shooter game I’m making but the way it works lets me walk through walls and I don’t want it to do that.

var upSpeed : float = 10;
var leftSpeed : float = 10;
var rightSpeed : float = 10;
var downSpeed : float = 10;

function Update () {

if (Input.GetKey(KeyCode.W))
	{
		transform.Translate(Vector3.up * upSpeed * Time.deltaTime, Camera.main.transform);
	}

if (Input.GetKey(KeyCode.A))
	{
		transform.Translate(Vector3.left * leftSpeed * Time.deltaTime, Camera.main.transform);
	}
	
if (Input.GetKey(KeyCode.S))
	{
		transform.Translate(Vector3.down * downSpeed * Time.deltaTime, Camera.main.transform);
	}
	
if (Input.GetKey(KeyCode.D))
	{
		transform.Translate(Vector3.right * rightSpeed * Time.deltaTime, Camera.main.transform);
	}
}

Basically I want to be able to move my character up, left, right, and down regardless of where my player is looking (which is always at the mouse cursor). I got it to do that but now I can move through the terrain and other objects that have colliders.

Any help would be appreciated!

Not sure why you’re not using the generic 3rd person controller here. Would save you lots of effort and give you better results. But regardless, I’d say add the rigidbody and collider back on and move it by applying force and drag instead. The issue you had before was using transform on a rigidbody. When you hit another collider using transform, the colliders overlap a bit too much since you’re basically teleporting the object by a set distance per frame. When colliders overlap weird things happen.

You’ll need to handle collision response yourself. I’d set my colliders to triggers and use onTriggerEnter to detect the collision, then I’d disable movement in the appropriate direction and correct the transform’s position in case it went too far into the wall.