Godot Version
4.4.1
Question
I’m pretty new to Godot and fooling around trying to get a first person perspective with a static camera. Imagine a light gun game or on rail shooter where you just shoot at your cursor and you don’t actually control the camera. I’ve tried finding a tutorial but I keep finding ones where the shooting mechanic is tied to the camera moving as well. Any ideas or angles of how I should tackle this mechanic would be appreciated!
1 Like
I do something similar for detecting interactable objects, so I child a RayCast3D to the Camera and use the following code.
var mouse := get_viewport().get_mouse_position()
var normal := $Camera.project_local_ray_normal(mouse)
$Camera/RayCast3D.target_position = normal * RAY_LENGTH
This has the downside of being off by a frame, but I find it’s easy to deal with if I want constant raycasts. If you only need to raycast on occasion, such as firing, then you may want to use a physics query instead.
2 Likes