- Home /
Question by
CG-DJ · Aug 13, 2013 at 03:35 AM ·
rigidbodymoveplatformercharacter controller
Problems with CharacterController.Move
Hi,
I am trying to make a Main Character for a 2D platformer. I'm using a CharacterController. The problem is, when I try to use (a modified version of)the script from the CharacterController.Move example, it doesn't quite work. I can move left (velocityX < 0) but it won't move right. Even when velocityX is positive, my cube won't move right!!!
I'm totally confused, any suggestions?
var speed : float;
var jumpForce : float;
var velocityX : float;
var velocityY : float;
private var controller : CharacterController;
private var gravity : float;
function Start ()
{
gravity = -Physics.gravity.y;
controller = GetComponent(CharacterController);
}
function Update ()
{
if(controller.isGrounded)
{
if(Input.GetAxis("Horizontal") > 0)
{
velocityX += speed;
}
if(Input.GetAxis("Horizontal") < 0)
{
velocityX -= speed;
}
if(Input.GetButtonDown("up"))
{
velocityY = jumpForce;
}
}
//Add Gravity
velocityY -= gravity * Time.deltaTime;
//Move Controller
controller.Move(Vector3(velocityX, velocityY, 0) * Time.deltaTime);
}
Comment
AH-HA! I didn't realize colliders on the children would affect anything. Thanks a bunch!
Best Answer
Answer by robertbu · Aug 13, 2013 at 03:48 AM
I tried the above script on a cube, and it worked (both directions). Any chance your character has children with colliders? If so, turn the colliders off on the children.