- Home /
Question by
Alex_Randelovic · Jul 19, 2017 at 10:21 AM ·
movement3d
How to make the player move without user input
Hi, I'm making a game and I'm stuck on this for ages. How to make the player move in a certain direction without user input. Please, could you help me I'm new to Unity?
Comment
Answer by Getsumi3 · Jul 19, 2017 at 10:35 AM
If you want your player to move without user input like in Subway Surfers or other runners you can try using Tranlate
https://docs.unity3d.com/ScriptReference/Transform.Translate.html Here is an example
public float speed = 10f;
private Vector3 dir;
void Start(){
dir = Vector3.forward; //Vector3(0, 0, 1)
}
void Update(){
float amountToMove = speed * Time.deltaTime;
transform.Translate (dir * amountToMove);
}
For more information about Transform.Translate
and others check Unity Scripting Reference https://docs.unity3d.com/ScriptReference/Transform.Translate.html
Your answer
