Search Unity

CharacterController.Move() moves player upward

Discussion in 'Scripting' started by hero_kenshin, Dec 21, 2014.

  1. hero_kenshin

    hero_kenshin

    Joined:
    Feb 21, 2013
    Posts:
    6
    Hey guys, just trying to get some simple movement in using the CharacterController.Move() function. It works, sort of. the player moves forward, but also moves upwards on the Y axis for some unknown reason. The movement code is:

    Code (CSharp):
    1. moveDirection = transform.TransformDirection(Vector3.forward);
    2. moveDirection *= walkspeed;
    3. moveDirection.y -= gravity;
    4. controller.Move( moveDirection *Time.deltaTime );
    I've been watching the Y co-ords in the editor and it always snaps to -11.55 every time i hold the button to move, but after releasing the button the character will fall back down to the ground.

    Any help figuring out why would be greatly appreciated. Thank you
     
  2. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    have you tried freezing the position on the rigidbody?
     
  3. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Code (CSharp):
    1. moveDirection.y -= gravity;
    Is this a serious thread?
     
  4. hero_kenshin

    hero_kenshin

    Joined:
    Feb 21, 2013
    Posts:
    6
    Freezing the rigidbody stops the character from falling to the ground, so he floats all the time.

    Yes.

    With or without that line of code it still doesn't work