- Home /
 
 
               Question by 
               unityappgames · Apr 11, 2013 at 04:24 PM · 
                javascriptmove  
              
 
              Move Object Left/ Right
Hi Guys,
I'm using JavaScript and I have One BIG problem.
This is the script I use:
 var moveTouchPad : Joystick;
 var rotateTouchPad : Joystick;
 
 var cameraPivot : Transform;
 
 var forwardSpeed : float = 0;
 var backwardSpeed : float = 80;
 var sidestepSpeed : float = 80;
 var jumpSpeed : float = 0;
 var inAirMultiplier : float = 0;
 var rotationSpeed : Vector2 = Vector2( 0, 0 );
 var tiltPositiveYAxis = 0;
 var tiltNegativeYAxis = 0;
 var tiltXAxisMinimum = 0;
 
 private var thisTransform : Transform;
 private var character : CharacterController;
 private var cameraVelocity : Vector3;
 private var velocity : Vector3;
 private var canJump = true;
 
 function Start()
 {        
     thisTransform = GetComponent( Transform );
     character = GetComponent( CharacterController );    
 
     var spawn = GameObject.Find( "PlayerSpawn" );
     if ( spawn )
         thisTransform.position = spawn.transform.position;
 }
 
 function OnEndGame()
 {    
     moveTouchPad.Disable();
     
     if ( rotateTouchPad )
         rotateTouchPad.Disable();    
 
     this.enabled = false;
 }
 
 function Update()
 {
     var movement = thisTransform.TransformDirection( Vector3( moveTouchPad.position.x, 0, moveTouchPad.position.y ) );
 
     movement.y = 0;
     movement.Normalize();
 
     var absJoyPos = Vector2( Mathf.Abs( moveTouchPad.position.x ), Mathf.Abs( moveTouchPad.position.y ) );    
     if ( absJoyPos.y > absJoyPos.x )
     {
         if ( moveTouchPad.position.y > 0 )
             movement *= forwardSpeed * absJoyPos.y;
         else
             movement *= backwardSpeed * absJoyPos.y;
     }
     else
         movement *= sidestepSpeed * absJoyPos.x;        
 
     if ( character.isGrounded )
     {        
         var jump = false;
         var touchPad : Joystick;
         if ( rotateTouchPad )
             touchPad = rotateTouchPad;
         else
             touchPad = moveTouchPad;
     
         if ( !touchPad.IsFingerDown() )
             canJump = true;
         
          if ( canJump && touchPad.tapCount >= 2 )
          {
             jump = true;
             canJump = false;
          }    
         
         if ( jump )
         {        
             velocity = character.velocity;
             velocity.y = jumpSpeed;    
         }
     }
     else
     {
         velocity.y += Physics.gravity.y * Time.deltaTime;
 
         movement.x *= inAirMultiplier;
         movement.z *= inAirMultiplier;
     }
 
               But this is not how I want it, I try to make it like Subway Surfer
If i slide to the Left, the object should go to the left with by example XAxis=80 And otherwise with the Right.
This is where I think about.
Is There SOMEONE who can help me change my script?
Thanks in advance
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help with plat-former character rotate 1 Answer
Too many bugs 0 Answers
What is a good unityscript writing program? 1 Answer
JavaScript Version of foreach (Touch touch in Input.touches) 1 Answer