- Home /
Character Controller Collision
My character isn't colliding with objects head on he just walks right through them. If he jumps and lands on them the collision works great he can sit on top of any cube I create it's just when he hits them head on walking forward or backward. The only thing I can think of is how I am moving the controller maybe? Code and controller settings below, any ideas?
Character Controller Settings: Slope Limit = 45, Step Offset = .3, Skin Width = .08, Min Move Distance = 0
var walkSpeed : float = 5.0;
var jump : float = 5.0;
var gravity : float = 9.8;
var player : GameObject;
var runSpeed : float = 8.0;
private var jumpNumber : int = 0;
private var moveDirection = Vector3.zero;
private var speed : float = 5.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Adds Gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
//Walk Right
if(Input.GetButton("MoveRight"))
{
//animation["Walk"].speed = 1.5;
transform.Translate(Vector3.right * Time.deltaTime * speed);
}
//Walk Left
if(Input.GetButton("MoveLeft"))
{
transform.Translate(Vector3.left * Time.deltaTime * speed);
}
//Double Jump
if(controller.isGrounded)
{
jumpNumber = 0;
}
if(Input.GetButtonDown("Jump") && jumpNumber < 2)
{
moveDirection.y= jump;
jumpNumber ++;
}
//Reset on Death
if(player.transform.position.y <= -20)
{
Application.LoadLevel("Squish");
}
//Sprint Function
if(Input.GetButtonDown("Run") && controller.isGrounded)
{
speed = runSpeed;
}
//Sprint Function Release
if(Input.GetButtonUp("Run"))
{
speed = walkSpeed;
}
}
Check the collider to see if it reaches down to the character controller.
Answer by VictoryX · Mar 07, 2013 at 04:45 AM
I figured out that if I changed
//Walk Right
if(Input.GetButton("MoveRight"))
{
//animation["Walk"].speed = 1.5;
transform.Translate(Vector3.right * Time.deltaTime * speed);
}
//Walk Left
if(Input.GetButton("MoveLeft"))
{
transform.Translate(Vector3.left * Time.deltaTime * speed);
}
To this
//Walk Right
if(Input.GetButtonDown("MoveRight"))
{
moveDirection.x = speed;
}
//Walk Left
if(Input.GetButtonDown("MoveLeft"))
{
moveDirection.x = -speed;
}
The collision works perfectly fine. So it was the way I was moving my character around that caused it.
Answer by ManeGuitar123 · Mar 07, 2013 at 01:12 AM
i know that you need to put a mesh collider on components
Okay, okay, I was just checking. Whats your floor like? Anything special?
Here's a video link to what the problem is. http://youtu.be/X8tq38HgD2c
Answer by LightSource · Mar 07, 2013 at 01:59 AM
Try it with a first person character controller (Assets > Import Package > Character Controllers). Are your using the character controller movement script?
If that does not work it a problem with the cube.
If it works it a problem with the collider.
If its a problem with the collider, what I recommend is to change the character controller to the shape you want and retexture it (make it your previous charater). I also see your controllers collider has an unnatural shape, change that to fit the character more securely, it may be conflicting with the cubes box.
If its a problem with the cube, try changing the material and adding a different cube higher above the floor. Also, make sure no scripts are referencing it.
Good luck!
I'm using my own movement script which is pretty much a Frankenstein of stuff I find online and help I get here on the forum. I imported the 1st person package and that works/collides fine. I've tried re-shaping the controller collider a bunch of different ways to no effect. I tried adding a mesh collider that would use my models mesh but it won't let me with the character controller on there. How do people use character controllers on their custom characters? The only options for a collider is a capsule shape and a sphere shape on it. $$anonymous$$y only thought is how I'm moving the character in script somehow overrides my collision.
Answer by MorphVGX · Aug 11, 2015 at 03:10 AM
You should use this: http://docs.unity3d.com/ScriptReference/CharacterController.Move.html