How do I execute transform.translate using accelerometer on PC?,
Hi. Thanks for stopping by. I have a very simple scene. An airplane flies through the rings and a point is awarded. I want the x and y axes to be controlled with a cellphone's aceelerometer. The game must run on PC, however. I have tried numerous solutions that I have found online including the official documentation for the new Input System but no dice. Any help would be appreciated. Working code with keyboard inputs. Using translate as there are no physics involved but if there is a better options, please let me know. Thanks in advanced! 30 second YouTube video for reference: https://youtu.be/GxhwGTF23oA
public class PlayerController : MonoBehaviour
{
[SerializeField]
private int speed = 10;
private int bankSpeed = -10;
public int points;
UIManager uimanager;
// Start is called before the first frame update
void Start()
{
uimanager = GameObject.Find("Canvas").GetComponent<UIManager>();
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.right * speed * horizontalInput * Time.deltaTime * 3.0f);
transform.Translate(Vector3.up * bankSpeed * verticalInput * Time.deltaTime * 3.0f);
}
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Torus")
{
points += 1;
uimanager.UpdatePoints(points);
}
}
}
Your answer
Follow this Question
Related Questions
How to calibrate phone acceleratormeter data? 0 Answers
Motion based Gesture recognition using accelerometer or gyroscope 1 Answer
Funky Flying Quaternion Question 0 Answers
Pokio Jump Mechanic (Mario Odyssey) 0 Answers
Android Roll-a-ball jump? 0 Answers