0 votes

Hi, thank you for clicking on my question!

So here is how my code looks like currently:

func _input(event):
    if event is InputEventMouseMotion:
        rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
        Head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))

It works fine on a flat surface, but on a spherical one, the right and the left rotations are gradually switched, while the player walking toward the opposite side.

Here is a video of my problem (It's hard to demonstrate it well):

https://youtu.be/_NaoIc51Ck4 (I always move the mouse the same amount)

Any help is greatly appreciated!

in Projects by (30 points)
edited by

I am new to Godot but from your description of your problem i would suggest to try reading up on global and local space. there is not really enough here for someone who knows to give a specific answer but on the top of a scene tab there is a button to toggle between global and local space, experimenting with that may be a place to start.

Thank you for your answer! I read up on global and local space, like you said, and tried applying what I knew to my code. I couldn't get it to work so far, but I'll be trying some more. I know the button you are talking about, but I'm afraid it only affects the editor, and not the game itself.

1 Answer

0 votes
Best answer

Okay, so it turns out the problem was not what I expected. Here is the solution:

func _input(event):
if event is InputEventMouseMotion:
    rotate_object_local(Vector3.BACK, deg2rad(-event.get_relative().x * mouse_sensitivity))
    Head.rotate_x(deg2rad(-event.get_relative().y * mouse_sensitivity))

The other one didn't work, because it rotated the player on the global axis.

by (30 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.