Question by
Alex_lemes · Sep 15, 2018 at 12:25 PM ·
movementcharacter controller
Character Controller (component) unwanted movement
Hello,
I've been trying to get my character controller working and I literally just took the code from Unity documentation for a starting point (https://docs.unity3d.com/ScriptReference/CharacterController.Move.html), however, this code works until I stop moving and then my character just randomly start moving in the opposite direction. After looking online it looked like a problem with my collider as I kept it on but found out the character controller has its own collider, so I removed the one I had and the issue still occurred.
Anyone else had this issue or a solution?
Thanks!
My Code:
if (characterController.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
Comment
Best Answer
Answer by Alex_lemes · Sep 17, 2018 at 12:54 PM
never mind fixed it.
How did you fix it?,How did you fix it? I have the same problem @$$anonymous$$_lemes