+1 vote

I'm fairly new to Godot but I've used Unity before. I am trying to implement a 3D Mouselook system. In Unity I can get the horizontal Mouse movement with this:

Input.GetAxis ("Mouse X");

What is the equivalent of this in Godot? How do I get the amount of mouse movement? I can't seem to find anything useful under Godot's Input class.

in Engine by

code

enter image description here

code example use function  unhandledInput for capture mouse motion positon

    public override void _UnhandledInput(InputEvent @event)
{
    if (@event is InputEventMouseMotion eventMouseMotion)
    {
        //GD.Print(eventMouseMotion.Position);

        vertical = eventMouseMotion.Position.x * 5;

        horizontal = eventMouseMotion.Position.y * 5;

    }
}

1 Answer

0 votes
Best answer

I have figured out how to get mouse movement, but it's not something directly equivalent to Unity's Input.GetAxis("Mouse X").

public override void _Input(InputEvent motionUnknown) {
    InputEventMouseMotion motion = motionUnknown as InputEventMouseMotion;
    if (motion != null) {
        // if we get here, then the input is mouse movement
        // and it's now in the variable "motion"
        // do something with "motion.Relative" which is the movement Vector2
    }
}
by
selected
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 webma[email protected]g with your username.