- Home /
 
 
               Question by 
               Zitoox · Jul 14, 2016 at 08:39 PM · 
                scripting beginnerkeyboardmove an objectusingwithout  
              
 
              Help with auto moving script
I am new to scripting, and i don't know much of it. I need help with making a Auto-Moving script. I am making a endless runner, and i made a script that makes my player go forward as it press W, using rigidbody. But, how can i make a script that makes the player go forward even if he is not pressing any key? Like a Auto-move.
This is my script:
 using UnityEngine;
 using System.Collections;
 
 public class goahead : MonoBehaviour
 {
 
     public float speed = 1f;
 
     void Update()
     {
         transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * Time.deltaTime * speed);
     }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by vintar · Jul 14, 2016 at 09:00 PM
You would do something like this :
 void Update()
 {
     transform.position = transform.position + (transform.forward * speed * Time.deltaTime);
 }
 
              Your answer
 
             Follow this Question
Related Questions
how to get my gui keyboard input work ? 0 Answers
How to set closeKeyboardOnOutsideTap? 0 Answers
How to get a key hold to do something which is stored in a variable as KeyCode ? 1 Answer
Question out of Curiosity involving namespaces 1 Answer
Unity 2D: How to move object in an pre defined path? 2 Answers