- Home /
 
              This question was 
             closed Dec 09, 2014 at 03:55 PM by 
             unimechanic for the following reason: 
             
 
            Too subjective and argumentative
 
               Question by 
               Caseyrozzelcopter · Dec 05, 2014 at 02:29 PM · 
                jumpjumpingrunsprint  
              
 
              How do I script so my character Jumps farther when Running?
My character's Walk Jump distance and Run Jump distance are the same. I have the code for running and crouching below. How can I add onto this to make my character's jump distance farther while running?
  var walkSpeed: float = 7; // regular speed
  var crchSpeed: float = 3; // crouching speed
  var runSpeed: float = 20; // run speed
  
  private var chMotor: CharacterMotor;
  private var tr: Transform;
  private var dist: float; // distance to ground
  
  function Start(){
      chMotor = GetComponent(CharacterMotor);
      tr = transform;
      var ch:CharacterController = GetComponent(CharacterController);
      dist = ch.height/2; // calculate distance to ground
  }
  
  function Update(){
  
      var vScale = 1.0;
      var speed = walkSpeed;
      
      if (chMotor.grounded && Input.GetKey("left shift") || Input.GetKey("right shift")){
          speed = runSpeed;
      }
      if (Input.GetKey("c")){ // press C to crouch
          vScale = 0.5;
          speed = crchSpeed; // slow down when crouching
      }
      chMotor.movement.maxForwardSpeed = speed; // set max speed
      var ultScale = tr.localScale.y; // crouch/stand up smoothly 
      tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
      tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
  
  
 }
 
              
               Comment
              
 
               
              Answer by unimechanic · Dec 09, 2014 at 03:55 PM
Please check our tutorial section: https://unity3d.com/learn/tutorials/modules