- Home /
 
               Question by 
               lixpoxx · Apr 18, 2014 at 08:47 AM · 
                charactercharactercontrollercontrollerjumpgrounded  
              
 
              Let Character Controller jump.
Hello. The game I'm working on only requires jumping. I'm using a character controller to do so. This is my script:
 function Update(){ 
 var controller : CharacterController = GetComponent(CharacterController); 
 if(Input.GetButton("Jump")){
     if (controller.isGrounded){
         transform.Translate(Vector3.forward * jumpSpeed * Time.deltaTime);
     } 
 }
I tried everything, but my player does't seem that he wants to jump. Please help me!
               Comment
              
 
               
              Try the following:
 var $$anonymous$$oveVector : Vector3;
 var JumpSpeed = 10;
 var Speed = 5;
 var gravity = 20;
 
 function Update()
 {
     var controller : CharacterController = GetComponent(CharacterController);
 
     if(controller.isGrounded)
     {
         $$anonymous$$oveVector = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     
         $$anonymous$$oveVector = transform.TransformDirection($$anonymous$$oveVector)
         $$anonymous$$oveVector *= Speed;
 
         if(Input.GetButtonDown("Jump"))
             $$anonymous$$oveVector.y = JumpSpeed;
     }
     
     $$anonymous$$oveVector.y -= gravity * Time.deltaTime;
     controller.$$anonymous$$ove($$anonymous$$oveVector * Time.deltaTime);
 }
Where the $$anonymous$$oveVector is modified in the update to match your input, and some little calculations for gravity and jumping. Hope this helps!
Your answer
 
 
             Follow this Question
Related Questions
Let Character Controller jump. 1 Answer
How to fix a infinity jump? 1 Answer
Custom Character Script Allowing Movement in the Air? 0 Answers
fps script not working 1 Answer
why does character controller accelerate off ledges? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                