COLLIDERS

i have created a 3rd person game. everything works fine apart from my player doesnt collide with anything.

‘generate colliders’ is turned on for all the geometry in the level(including the player), but the player just walks straight through everything.

any ideas?

Do any of your objects have rigidbodies attached to them?

For colliders to work one of the colliding objects needs to have a rigidbody component.

If you haven’t, attach a rigidbody component to the object you are controlling.

thanks for the reply,

i just tried adding a rigid body to the player and it doesnt seem to do anything, however when gravity is turned on, the player falls throught the floor.

would really appreciate some more help with this

If you’re using a CharacterController for the player, then make sure you are moving it using the Move/SimpleMove methods and not by directly moving the transform. It will probably help you to have a rigidbody on the player in any case, but you can turn off the physics for it by setting its isKinematic property to true.

yep, ive tried all this, the player still just walks through everything.

no idea where im going wrong.

You mean you set this in the 3D modelling app? Unity won’t recognise that - you have to add a MeshCollider component (menu Component > Physics > Mesh Collider).

hi,

‘generate colliders’ is checked in the inspector in unity.

just tried adding a mesh collider, hasnt made any difference.

OK… try making the mesh colliders convex. Also, is it possible you’ve enabled detectCollisions on the CharacterController from a script?

If this doesn’t fix it, would you be able to post the project (or contact support@unity3d.com about it if you don’t want it publicly visible)?

how would i post the project on here? the whole project folder is about 500mb.

im still having trouble with this.

the player is just walking through everything in the level.

any other ideas what it could be?

If you can’t post the project, it would help if you would post a screen shot of the settings of one of the colliders that doesn’t work, a screen shot of the settings of your character controller and the code moving your player.

hi,

here is the character controller script -

var turnSpeed = 10.0; 
var moveSpeed = 10.0; 
var mouseTurnMultiplier = 1; 

private var x : float; 
private var z : float; 
function Update () 
{ 
   // x is used for the x axis.  set it to zero so it doesn't automatically rotate 
   x = 0; 
    
   // check to see if the W or S key is being pressed.  
   z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed; 
    
   // Move the character forwards or backwards 
   transform.Translate(0, 0, z); 
          
   // Check to see if the A or S key are being pressed 
   if (Input.GetAxis("Horizontal")) 
   { 
      // Get the A or S key (-1 or 1) 
      x = Input.GetAxis("Horizontal"); 
   } 
    
   // Check to see if the right mouse button is pressed 
   if (Input.GetMouseButton(1)) 
   { 
      // Get the difference in horizontal mouse movement 
      x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier; 
   } 

   // rotate the character based on the x value 
   transform.Rotate(0, x, 0); 
}

here is a screenshot of the player collider -

246492--8862--$player_collider_978.jpg

You need to use physics if you want any collisions.

–Eric

what does the first person controller have that i dont?

It uses physics, namely CharacterController.Move(). If you just set the position explicitly, it won’t work because that overrides any physics. Either modify the first person controller, or use one of the third person controllers from the Lerpz tutorial or others.

–Eric

i have tried everything i can think of including editing the lerpz script etc. but i cant seem to get what i want.

here is my script -

var turnSpeed = 10.0; 
var moveSpeed = 10.0; 
var mouseTurnMultiplier = 1; 

private var x : float; 
private var z : float; 
function Update () 
{ 
   // x is used for the x axis.  set it to zero so it doesn't automatically rotate 
   x = 0; 
    
   // check to see if the W or S key is being pressed.  
   z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed; 
    
   // Move the character forwards or backwards 
   transform.Translate(0, 0, z); 
          
   // Check to see if the A or S key are being pressed 
   if (Input.GetAxis("Horizontal")) 
   { 
      // Get the A or S key (-1 or 1) 
      x = Input.GetAxis("Horizontal"); 
   } 
    
   // Check to see if the right mouse button is pressed 
   if (Input.GetMouseButton(1)) 
   { 
      // Get the difference in horizontal mouse movement 
      x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier; 
   } 

   // rotate the character based on the x value 
   transform.Rotate(0, x, 0); 
      
	// Move the controller
	var controller : CharacterController = GetComponent(CharacterController);
	}

the script works perfectly for controlling my player. its just that he walks through things.

can someone please tell me what i need to add/change to my script to get it to work?

I really need some help on this.

thanks

Just getting the CharacterController component doesn’t move the object. The controller has a function called Move that you have to call to get the right collision effect. I’ve modified your script to show this, but I’ve left the transform.Translate line commented out to explain the difference.

var turnSpeed = 10.0; 
var moveSpeed = 10.0; 
var mouseTurnMultiplier = 1; 

private var x : float; 
private var z : float;

var controller: CharacterController;


function Start() {
	// Get a reference to the controller 
   controller : CharacterController = GetComponent(CharacterController); 
}


function Update () 
{ 
   // x is used for the x axis.  set it to zero so it doesn't automatically rotate 
   x = 0; 
    
   // check to see if the W or S key is being pressed.  
   z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed; 
    
   // Move the character forwards or backwards 
   // transform.Translate(0, 0, z);
   
   controller.Move(new Vector3(0, 0, z);
          
   // Check to see if the A or S key are being pressed 
   if (Input.GetAxis("Horizontal")) 
   { 
      // Get the A or S key (-1 or 1) 
      x = Input.GetAxis("Horizontal"); 
   } 
    
   // Check to see if the right mouse button is pressed 
   if (Input.GetMouseButton(1)) 
   { 
      // Get the difference in horizontal mouse movement 
      x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier; 
   } 

   // rotate the character based on the x value 
   transform.Rotate(0, x, 0); 
   }

hi,

this works perfectly thanks.

although, when i turn left or right, the character turns very slowly and when i change the ‘turn speed’ it doesnt seem to make a difference.

is there a way of making him turn faster?

thanks

The turn speed doesn’t seem to be used when you turn with the keys. Multiply the Input.GetAxis value by turnSpeed to make this happen.