generate functionMon, 20 Feb 2023

Unity 2d object movement using accelerometer

void Update() { //Get the Input from Horizontal axis float moveHorizontal = Input.GetAxis ("Horizontal"); //Get the Input from Vertical axis float moveVertical = Input.GetAxis ("Vertical"); //Update the Rigidbody 2d velocity according to the axis input rb2d.velocity = new Vector2 (moveHorizontal * maxSpeed, moveVertical * maxSpeed); }

Questions about programming?Chat with your personal AI assistant