#Making a Camera3D to look at mouse position (first-person)

1 messages · Page 1 of 1 (latest)

vague patio
#

What I do know: how to get mouse position in current viewport, how ray-casting works in theory. What I don't know: literally everything else.

#

Obviously I'll be doing research about the subject in the meanwhile, so I don't expect you to explain everything for me from the ground-up.

vague patio
#

Reading about the subject, I now know how to project rays from my camera. How can I use that information then to rotate my view?

vocal sentinel
#

if you mean an ordinary first person camera from an FPS, wasd + mouse style, this would not normally be done with ray casting

#

you might search for ‘fps controls’ instead

vague patio
#

So I found this code snippet online:

#

func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
var sensitivity = 0.2
var rotation = -event.relative.x * sensitivity
rotation.y += -event.relative.y * sensitivity
rotation.x = clamp(rotation.x, -90, 90)
camera.rotate_x(rotation.y)
rotate_y(rotation.x)

#

I understand what it's doing until line 4 (var rotation = -etc...)

#

Documentation says that rotation shouldn't be used, but instead transform.basis

#

I am taking this question to forums, because I am not getting the conversation I seek. Thanks anyways 🙂