0 votes

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.

in Engine by (14 points)

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 ?

1 Answer

+1 vote

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

https://www.youtube.com/watch?v=CeNXDSkv5v8

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.