Search
Inifinite Runner Testing Phase
- Marc Fasulo
- Jun 19, 2020
- 1 min read
I started to learn how to code in Unity and was able to control the player with the A and D keys going left and right as it goes down the track.

This is the code that I typed in Microsoft Visual Studio
public class PlayerMovement2 : MonoBehaviour {
public Rigidbody playerRB;
public int speed;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void FixedUpdate() {
float newSpeed = speed * Time.deltaTime;
playerRB.AddForce(0, 0, newSpeed);
if(Input.GetKey("d"))
{
playerRB.AddForce(20, 0, 0);
}
if(Input.GetKey("a"))
{
playerRB.AddForce(-20, 0, 0);
}
}
}
Comments