-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mobile Sensors Demo GyroAndGrav rotation inaccurate #988
Comments
Managed to make a demo without this effect (this works as a script for any Node3D): var yaw = 0
var old_up
var k : float = 0
func _ready():
old_up = -1 * Input.get_gravity()
func _physics_process(delta):
var up = -1 * Input.get_gravity()
var angle = up.angle_to(Vector3.UP)
var axis = up.cross(Vector3.UP).normalized()
transform.basis = Basis()
rotate_object_local(axis, angle)
var gyro = Input.get_gyroscope()
var x_percentage = transform.basis.x.dot(Vector3.UP)
var y_percentage = transform.basis.y.dot(Vector3.UP)
var z_percentage = transform.basis.z.dot(Vector3.UP)
var up_projected = Vector2(up.x, up.z)
var old_up_projected = Vector2(old_up.x, old_up.z)
yaw -= (1 - y_percentage) * up_projected.angle_to(old_up_projected)
yaw += delta * x_percentage * gyro.x
yaw += delta * y_percentage * gyro.y
yaw += delta * z_percentage * gyro.z
rotate_y(yaw)
old_up = up |
Which Godot version are you using? PS: Code blocks should use triple backticks like this (with an optional language name for syntax highlighting): ```gdscript I edited your post accordingly, but remember to do this in the future 🙂 |
Ah many thanks, was struggling with that. I am using Godot 4.1, sorry for not mentioning that earlier. |
Note: This effect happens in the demo too if one comments out the line: yaw -= (1 - y_percentage) * up_projected.angle_to(old_up_projected) It is there to combat the incorrect yaw inference made by rotating the basis in an effort to match the y axis to the gravity vector. |
In the demo project "Mobile Sensors Demo" the GyroAndGrav cube is rotated incorrectly when the phone is tilted on its side and then tilted up and down. When you do this, the cube is erroneously also rotates around the real world y axis, which does not correspond to the actual orientation of the phone.
The text was updated successfully, but these errors were encountered: