- Home /
 
 
               Question by 
               Desination-X · Aug 01, 2014 at 10:13 PM · 
                movementcharacterfly  
              
 
              When I look down and move forward, I fly upwards
I have my own super basic movement script, and everytime I walk forward while looking down, my character goes upwards at an angle. It goes up and forward, if that makes sense.
I did some research and found people who had similar problems, but no one with the problem I am having.
Any idea why this is happening? Oh, and on a side note, even though my walk speed is 0.1, my character is still relatively fast.
Here is my script:
 using UnityEngine;
 using System.Collections;
 
 public class CharacterMovement : MonoBehaviour {
     
     public float walkSpeed = 0.1F;
     public float runSpeed = 1.0F;
     public float jumpSpeed = 5.0F; 
     public float gravity = 20.0F;
     public float jumpTimer = 1.5F;
 
     public bool sprinting;
 
     CharacterController controller;
 
     private Vector3 moveDirection = Vector3.zero;
 
     private bool canJump = true;
 
     PlayerInventory playerInventory;
 
     DebugConsole debugConsole;
 
     void Start () {
         controller = GetComponent<CharacterController>();
         playerInventory = GetComponent<PlayerInventory>();
         debugConsole = GameObject.Find ("_SCRIPTS").GetComponent<DebugConsole>();
     }
 
     // Update is called once per frame
     void Update () {
         if(controller.isGrounded && !PauseMenu.paused && !debugConsole.commandLine && !playerInventory.inInventory){
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
 
             if(Input.GetKeyDown(KeyCode.LeftShift) && Player.Stamina > 0)
                 sprinting = true;
             if(Input.GetKeyUp(KeyCode.LeftShift))
                 sprinting = false;
 
             if(sprinting)
                 moveDirection *= runSpeed;
             else
                 moveDirection *= walkSpeed;
 
             if (Input.GetButton("Jump") && canJump && Player.Stamina > 10){
                 canJump = false;
                 StartCoroutine(jumpDelay());
                 moveDirection.y = jumpSpeed;
                 Player.setStamina(-5);
             }
         }
 
         moveDirection.y -= gravity * Time.deltaTime;
 
         controller.Move(moveDirection);
     }
 
     IEnumerator jumpDelay () {
         yield return new WaitForSeconds(jumpTimer);
         canJump = true;
     }
 
 }
 
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Edit this code? 0 Answers
Space Invaders movement? 1 Answer
BCE0044: Expecting : Found = Error! 2 Answers
Controlling AI Movement 0 Answers