- Home /
 
               Question by 
               ani2020.bhandari · Dec 19, 2012 at 03:40 PM · 
                gamejumprunside  
              
 
              Help Me with My Script Pls??????
- List item 
So, I am Trying To make A temple run game and i am not able to jump or make it go side ways Please Help following is my Script
     public var speed = 10.0f; 
     var jumpSpeed = 20.0f;
  var gravity =20.0f;
  private var moveDirection = Vector3.zero;
  private var grounded :
  boolean = false; var coin = 0; var
      coinText = "coin: 0";
     var sideSpeed =12;
      
      function Start(){ // Set all
      animations to loop   
      animation.wrapMode = WrapMode.Loop;   
      // except shooting   
      animation["side"].wrapMode =
      WrapMode.Once;   
      animation["side"].layer = 1;   
      animation["jump"].wrapMode =
      WrapMode.Once;   
      animation["jump"].layer = 2;
      animation.Stop(); }
      
      
      function FixedUpdate() {
          if (grounded) {
          
          if (Mathf.Abs(Input.GetAxis("Vertical"))     <= 0.1){
             animation.CrossFade("run");
              
              }
              
           } 
                
               // We are grounded, so recalculate movedirection directly from axes
          moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
              moveDirection = transform.TransformDirection(moveDirection);
              moveDirection *= speed;
                if(Input.GetButtonDown("side")){
              animation.CrossFade("side");
              }
              
                if(Input.GetButtonDown("Jump")) {
      moveDirection.y = jumpSpeed; }
       
       
          if(Input.GetButtonDown("Jump")) {
       
          animation.CrossFade("jump");
          }
      
      // Apply gravity moveDirection.y -=
      gravity * Time.deltaTime;
      
      // Move the controller 
 `    `var controller
      : CharacterController =
      GetComponent(CharacterController); var
      flags = controller.Move(moveDirection
      * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 `` }
      
      @script
      RequireComponent(CharacterController)
      
      
      function Update()  {
      transform.position +=
      transform.forward * speed *
      Time.deltaTime; 
          speed += 2.0 * Time.deltaTime;    }
      
      
       function OnTriggerEnter( other :     Collider ) {
          Debug.Log("OnTriggerEnter() was called");
          if (other.tag == "Gold") {
              Debug.Log("Other object is a coin");
             coin += 1;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          }
          if (other.tag == "Blue") {
              Debug.Log("Other object is a coin");
              coin += 2;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          }
          if (other.tag == "Red") {
              Debug.Log("Other object is a coin");
              coin += 3;
              coinText = "Score: " + coin;
              Debug.Log("Score is now " + coin);
              Destroy(other.gameObject);
          } }
      
      function OnGUI () {
           GUI.Label (Rect (10, 10, 100, 20), coinText);
  }
               Comment
              
 
               
              Answer by JaydenM1997111 · Dec 20, 2012 at 06:48 PM
         public var Player: GameObject;
         public var MoveOnX : float;
         public var MoveOnY : float;
         public var jumpHeight : float = 20;
         public var MoveSpeed : float = 2;
         public var DefaultPos : Vector3;
         public var NewPos : Vector3;
         
         function Start(){
             DefaultPos = transform.localposition; 
         }
         function Update () {
             MoveOnX = Input.GetAxis("Mouse X") * Time.deltaTime * MoveAmount;
                MoveOnY = Input.GetAxis("Mouse Y") * Time.deltaTime * MoveAmount;
                NewPos = new Vector3 (DefaultPos.x+MoveOnX, DefaultPos.y+MoveOnY, DefaultPos.z);
                Player.transform.localPosition = Vector3.Lerp(Player.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);
             
             if( Input.GetButtonDown("Jump")){
                  NewPos = new Vector3 (DefaultPos.x, DefaultPos.y+jumpHeight, DefaultPos.z);
                 Player.transform.localPosition = Vector3.Lerp(Player.transform.localPosition, NewPos, MoveSpeed*Time.deltaTime);
             }
         }
This code is to make your player jump and then slide back to its position :)
By doing this you create the jump with ease, just edit a few values :)
hope it works
Not Working But Thanx For trying And I Don't want to use my mouse for movement
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                