the problem is that you’re using translate, which can obviously work for movement but it doesn’t work incredibly well with the physics engine, which is why you’re having collision issues.
I strongly recommend you use the standard assets character controller prefabs, like the fps rigidid body or fps character controller. Which you can find in the assets menu and select character.
You could also quite easily add a character controller component to your character and add this code, which does the movement you’re trying to get Unity - Scripting API: CharacterController.Move
If you’re dead set on not using any components or prefabs, then you could possible try using raycasts as a method of collision.
you could then use:
var moveSpeed = 0.2;
var jumpHeight = .8;
var maxJumpHeight = 1;
function Start() {
}
function Update () {
//KeyBoard Inputs
if (Input.GetKey("w")) {
transform.Translate(Vector3(0, 0, moveSpeed));
CollisionDetection(new Vector3( 0, 0, moveSpeed));
}
if (Input.GetKey("s")) {
transform.Translate(Vector3(0, 0, -moveSpeed));
CollisionDetection(new Vector3( 0, 0, -moveSpeed));
}
if (Input.GetKey("a")) {
transform.Translate(Vector3(-moveSpeed, 0, 0));
CollisionDetection(new Vector3(-moveSpeed,0,0));
}
if (Input.GetKey("d")) {
transform.Translate(Vector3(moveSpeed, 0, 0));
CollisionDetection(new Vector3( moveSpeed,0,0));
}
if (Input.GetKey("space")) {
transform.Translate(Vector3(0, jumpHeight, 0));
}
}
void CollisionDetection(Vector3 moveVector)
{
if(Physics.Raycast(transform.position, moveVector, 1)
moveSpeed = 0;
else
movespeed = 0.2f;
}
This will detect if there is something in the direction you’re moving by using a raycast, and if there is, it will stop the character by speed, if not, it will return the speed to normal.
More on Raycasts here: Unity - Scripting API: Physics.Raycast
Again i strongly recommend you use the standard character assets or charactercontroller component unity provides, they’re incredibly well done.
hoped this helps