0 votes

Hi, i am making a game in which you use a gun that looks at the mouse. it follows the mouse nicely, but i need to get the exact rotation of the gun to calculate the knock back and the value exceeds 360 and goes on as i rotate it.

here's the code:

    look_at(get_global_mouse_position())
    if get_global_mouse_position().x > global_position.x:
        sprite.flip_v = false
    if get_global_mouse_position().x < global_position.x:
        sprite.flip_v = true
Godot version 3.5.1 stable
in Engine by (12 points)

1 Answer

+1 vote

You can wrap the gun's rotation within a defined range via the fmod method. You probably want something like this:

var wrapped_rotation = fmod(rotation_degrees, 360))
by (19,298 points)
edited by

Thanks, i have already solved it using

rotation = rotation%360

or something like that

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 Frequently asked questions and 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 [email protected] with your username.