Viewmodel camera FOV displaces barrel position

Godot Version

Godot 4.2.1


I’m making an FPS game and i render the guns with a subviewport and a camera with FOV=60, while the player’s camera FOV=115.
So when a gun shoots it also shows the bullet trail, which has to be rendered by the 115 FOV camera.

The problem is the trail start position(barrel position) is different in those 2 FOVs.


RED → desired start position
WHITE → actual position

Is there any way to displace the White sphere so it matches the Red sphere.

I have tried displacing with the camera backwards vector, but when the gun moves or rotates the point diverges.
If there is no solution, that is also useful as i can just make the point custom per gun and disable viewmodel customization.
Thanks for trying

Looked thru the camera3d docs and found some methods that seemed they would work. After a few tries i got it to work.

barrel_pos → node3d to keep track of where i wanted the barrel to be in space (from player camera pov)
z → screen position of the barrel from viewmodel_cam pov

Then i just set the barrel’s global_position to a projected position from player’s camera pov, using the screen position i wanted, and the distance of the barrel from the player’s camera