Question by 
               TyrantKoala · Jul 13, 2017 at 07:01 PM · 
                c#jumpingmovingcharacter movement  
              
 
              How can I prevent my player from flying when i use the space bar?
The problem is that I am trying to create a code that my character can easily move around and jump. The problem is that it I cant see to get it to jump decently. I am new to unity so any help is greatly appreciated, thank you. Here is my code
 void Update()
 {
     if (!isLocalPlayer)
     {
         return;
     }
     {
         CharacterController controller = GetComponent<CharacterController>();
         if (controller.isGrounded)
         SmoothCameraFollow.target = this.transform;
         {
             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);
     }
     var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
     var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
     transform.Rotate(0, x, 0);
     transform.Translate(0, 0, z);
     if (Input.GetKeyDown(KeyCode.F))
     {
         CmdFire();
     }
 }
   
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Unity Rigidbody fps controller jumps higher each time. 0 Answers
How to move a character in one direction only when jumping? 1 Answer
How can i make my player look at the same direction where its moving? [JOYSTICK ANDROID] 0 Answers
Jumping Problems 0 Answers
Character's jumping mechanism stuck into something invisible 1 Answer