How to make a 2D rigidbody vertically when input is via the gyroscope
Hello!
I wish to make a 2D rigidbody vertically (in relation to the real world - not the game world) when the player rotates their phone on the Z axis. It should always be moving towards the ceiling in the room where the player is in.
See images below. The cyan circle should move in the direction of the arrow. The rotation variable is getting the Gyroscope attitude in Update() and is successfully logging the z value to the console.
private void FixedUpdate()
{
if (gyroActive)
{
// Move the player via the gyroscope input
rb.velocity = new Vector2(-rotation.z, -rotation.z) * playerSpeed;
}
}
That is my current code. It's detecting the gyro and moving the circle but not in the way intended, and I don't know where to go from here!
I greatly appreciate any help and thank you in advance.
Your answer
Follow this Question
Related Questions
Im trying to make a player move 360 degree gyroscopic movement on my phone 0 Answers
Gyroscope Controls for FPS 0 Answers
Moving.Rotating a Raycast with Respect to Rotation 1 Answer
2D Joint motor ignores limits when rotated towards -x. 0 Answers
Converting 2D square movement direction to procedural animation 1 Answer