- Home /
How to Move Player in Particular Direction Without holding Down a Button?
Hello,
For iOS: (Player without a Character Controller)
I'm trying to find the best way to move my player (X and Y space) and I'm not sure the proper terms to search for.
More specifically: With the player already moving, I want to press UP DOWN LEFT or RIGHT button and change directions, but only after colliding with a trigger. Triggers (with appropriate tags) will be in many locations. Ultimately sending the player in one of four directions.
I also wanted to know if you could send the player in just one direction without holding down a particular button. So I would tap the right button (with Vector3.right?) and send the player on his way?
I found a similar code sample with a transform but I'm thinking it needs a different operator like rigidbody.velocity or something with force or movement.
Still very new to Unity JS so I apologize.
Thanks for any help you can provide !!!
Sample of code similar to what I need ???
 var isMoved = true;
 var change = false;
 
 function Update () {
 
 if (isMoved == true)
      transform.Translate(Vector3(1,0,0) * Time.deltaTime); 
 
 if (change == true)
      transform.Translate(Vector3(-1,0,0) * Time.deltaTime); 
 }
 
 function OnCollisionEnter (hit:Collision){
     if (hit.gameObject.tag == "wallRight")
 
         {
         isMoved = false;
         change = true;
         Debug.Log("hit");
         }
 
     if (hit.gameObject.tag == "wallLeft")
         {
         change = false;
         isMoved = true;
         Debug.Log("hit");
         }
 
 }
Your answer
 
 
             Follow this Question
Related Questions
Rigidbody movement 1 Answer
Movement script breaks colliders 1 Answer
Add Force At Player 0 Answers
Using Add Force for character control 1 Answer
How do you make collider interactions and movement smooth? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                