Rotate Y axis to mouse (3d)

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

Hi, i managed to get the position of the mouse in 3d and i want to rotate the Y axis of the player to that position, but i dont know how to get that angle. This is how i get the mouse position:

func _input(event):
if event is InputEventMouseMotion:
	var state = get_world().direct_space_state
	var camera = $Camera
	var from = camera.project_ray_origin(event.position)
	var to = from + camera.project_ray_normal(event.position) *50
	var ray_result = state.intersect_ray(from, to,[self])
	if ray_result:
		var p= ray_result["position"]

The game is like a top-down-shooter and the camera is not a child of the player or it will rotate with him and mess up the mouse position.

If I get that right you’re trying to rotate something along the y-axis, said rotation being dictated by the movements of the mouse ?

TheFamousRat | 2019-02-17 23:47

:bust_in_silhouette: Reply From: jboss1995

I have been looking at this too, one way I was thinking of doing it was:

float atan2( float y, float x )
Returns the arc tangent of y/x in radians. Use to get the angle of tangent y/x. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.

a = atan(0, -1) # a is 3.141593