What is wrong here

Today when I ran Unity, I bumped onto a strange problem. My player wasn’t colliding with anything, either level geometry or imported models. I tried to put a new character controller and delete the old one, nothing changed, checked the collision of the models - they all had collision. Than I replaced my script with the FPSWalker script, that’s already in Unity and the collision was fine. But I don’t see any problems in my script. What’s wrong with it?

My code:

var moveForward = 0.0;
var moveSideways = 0.0;
var speed = 7.0;
var gravity = 0.0;
var maxSpeed = 0.0;
var speedDecreaser = 80.0;
var speedIncreaser = 80.0;

function Update () {
	SpeedMod();
	moveDir = new Vector3(moveSideways, 0, moveForward);
	transform.Translate(moveDir*Time.deltaTime);
	transform.Rotate(0, Input.GetAxis ("Mouse X") * 5, 0); 
}


function SpeedMod () {

//Increasing the speed
	if(Input.GetKey("w"))
	{
		moveForward += speedIncreaser * Time.deltaTime;
		if(moveForward > maxSpeed)
		{
			moveForward = maxSpeed;
		}
	}
 
	if(Input.GetKey("s"))
	{
		moveForward -= speedIncreaser * Time.deltaTime;
		if(moveForward < -maxSpeed)
		{
			moveForward = -maxSpeed;
		}
	}
 
	if(Input.GetKey("a"))
	{
		moveSideways -= speedIncreaser * Time.deltaTime;
		if(moveSideways < -maxSpeed)
		{
			moveSideways = -maxSpeed;
		}
	}
 
	if(Input.GetKey("d"))
	{
		moveSideways += speedIncreaser * Time.deltaTime;
		if(moveSideways > maxSpeed)
		{
			moveSideways = maxSpeed;
		}
	}
 


	if(Input.GetKey("e"))
	{
		maxSpeed = 11.0;
	}
	else
	{
		maxSpeed = 6.0;
	}


//Decreasing the speed
if((Input.GetKey("w") == false)  (Input.GetKey("s") == false))
{
	if(moveForward != 0)
	{
		if(moveForward > 0)
		{
			moveForward -= speedDecreaser * Time.deltaTime;
		}
		else
		{
			moveForward += speedDecreaser * Time.deltaTime;
		}
	}
	
	if(moveForward > 0.0  moveForward <= Time.deltaTime*speedDecreaser)
	{
		moveForward = 0.0;
	}
	}
	
	if((Input.GetKey("a") == false)  (Input.GetKey("d") == false))
{
	
	if(moveSideways != 0)
	{
		if(moveSideways > 0)
		{
			moveSideways -= speedDecreaser * Time.deltaTime;
		}
		else
		{
			moveSideways += speedDecreaser * Time.deltaTime;
		}
	}
	
	
	
	if(moveSideways > 0.0  moveSideways <= Time.deltaTime*speedDecreaser)
	{
		moveSideways = 0.0;
	}
	}
}

I haven’t done too much in the way of collisions, but I thought the Translate/Rotate methods don’t run through the physics engine?

But the FPSWalker script is using them as well and doesn’t have any problems with the collision:

moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		transform.Translate(moveDirection*Time.deltaTime*speed);

AFAIK, the character controller doesn’t use Physics. It obeys the whole collision box thing, but isn’t effected by physics themselves.

Also check you’ve not accidentally disabled any scripts or deleted anything by accident.

use CharacterController.Move.
the fps walker uses it.
translate will only make the character do small teleports ignoring collisions.

// Move the controller
CharacterController.Move(moveDirection * Time.deltaTime);

this.

tranform.translate ignores collision and will not do what you want. CharacterController.Move is the simplest implementation to do what you want, but keep in mind that it does not account for gravity so you will have to apply that yourself.

Yeah, there goes my mistake. I was using it before, I don’t know where did it go. Thanks guys!