- Home /
Character controller move not working
Hi, I am having a problem with the Character controllers move function. Using this code(straight from the example):
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
When i press both down arrow key and either left or right arrow key( or s and a or d) the character moves diagonally however when the up arrow key and either left or right arrow key the character does not move diagonally but just sideways.
Is there a known bug with the character controllers move or am I doing something wrong?
EDIT: I solved the issue. My character had a cube representing the front of it(its just a capsule) and I forgot to remove the collider off this cube so when moving forward there were weird collision issues.
Thanks for posting your solution, spent an age trying to work out why nothing was moving.
I actually had no box collider on character, but added a cube on it just to see its direction...that cube had box collider on it. Thank you dude...you are my life saviour...damn you Unity...I alredy lost all hopes in Unity...UNITY ROC$$anonymous$$S, LONG LIVE TPB!
Your answer
Follow this Question
Related Questions
Character Controller follow mouse 2 Answers
move character controller smoothly to the object 1 Answer
Stop a Lerp from looping 3 Answers
Character controller wont move 0 Answers
Vector3.Slerp not working 2 Answers