how to "translate" gdscript: head.relative.x to gdnative c++?

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

Hi,
I’m new in Godot and I try to do some FPS controller with yt tutorial. How can I translate gdscript code:

func _input(event):
    if event is InputEventMouseMotion:
          head.rotate_y(deg2rad(event.relative.x * 0.3))

head is just a spatial node: onready var head = $Head

I have in my cpp file:

void godot::Player::_input(InputEvent* event)
{
	InputEventMouseMotion* m = Object::cast_to<InputEventMouseMotion>(event);

	Node* head = Object::cast_to<Node>(get_node("Head"));
	
	if (m)
	{
		//auto head_rotate_y = Object::cast_to<Spatial>(head)->rotate_y(Math::deg2rad());
	}
}

but I don’t know how to get access to “relative”, can you help me, please?

:bust_in_silhouette: Reply From: tmk3

I have had some research about vector math and I solve my problem.

void godot::Player::_input(InputEvent* event)
{
	InputEventMouseMotion* m = Object::cast_to<InputEventMouseMotion>(event);

	Node* head = Object::cast_to<Node>(get_node("Head"));
	
	if (m)
	{
		real_t x_axis_relative = m->get_relative().x;
		Object::cast_to<Spatial>(head)->rotate_y(Math::deg2rad(-x_axis_relative * mouse_sensitivity));

	}
}

maybe this can help somebody