[C#] How do I get Mouse movement in C#?

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

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.

code

ariel | 2019-09-02 01:20

enter image description here


    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;
       
    }
}

ariel | 2019-09-02 01:24

:bust_in_silhouette: Reply From: anonymous

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
	}
}