How to use accelerometer and magnetometer control camera toward to ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zszen John

I want simple rotate camera in a skybox center. Just rotation around and toward up or down. Use iphone 7p.


  1. The code don’t work well when look up or look down. Do you have any good solution.
  2. If I running the development app without connect xcode. The magnetomater don’t work.

here my code:

var angs = []

func _process(delta):
	var acce = Input.get_accelerometer()
#	var gyro = Input.get_gyroscope()
#	var grav = Input.get_gravity()
	var mag = Input.get_magnetometer()
#	rotate_y(mag.x)
#	rotate_x(acce.z)
	mag = mag.normalized()
	acce = acce.normalized()
#	var newang = Vector3(acce.z*.5*PI, -mag.x*2*PI,0)
#	rotation = smooth_value(newang)
#	print(['angavg',angavg])
#	rotation = newang

#	transform.basis = orientate_by_mag_and_grav(mag, grav)
#	transform.basis = orientate_by_mag_and_grav(mag, grav).orthonormalized()
	rotation = Vector3(acce.z*.4*PI,atan2(mag.z,mag.x),0)