How to propagate lighting from the scene into a viewport?

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

I have an FPS setup more or less like this:

- KinematicBody
    - Spatial (Head)
        - Camera
            - ViewportContainer
                - Viewport
                    - Camera
                    - Spatial (Equipped item)

I have 2 questions here:

  1. Is there another (perhaps more performant) way of preventing equipped items from penetrating walls? I know I could do a raycast and trigger a “push back”, but are there other ways?

  2. If this is indeed the best approach, how does one propagate the lighting from the scene to the “equipped item viewport”?

Thanks!

I would suggest the following setup:

KinematicBody (Script)
   - Spatial (Head)
   - Camera
       - Spatial (Item)
       - ViewportContainer
           - Viewport
               - Camera

func _ready():
    $Camera/ViewportContainer/Viewport.world = get_world()
    $Camera.culling_mask = $Camera.culling_mask ^ 2 # all layers except separate one for item
    $Camera/Spatial.layers = 2 # separate layer for item
    $Camera/ViewportContainer/Viewport/Camera.culling_mask = 2 # only item layer

This way, the item will belong to the main world, but will be drawn separately. But I’m not sure if this will work + You may have to sync the cameras in space

Mak | 2021-05-01 20:58

That was the exact solution, thanks a lot!

While experimenting with this, I found that the animations I had created for my character in first person were only affecting some of the bones inside the Viewport. No idea why, I tried debugging it, but I couldn’t even reproduce it with a clean project.

I had to follow your suggestion exactly make it all work, so the only child of the viewport is the camera (which I did have to sync up).

Jeppe Zapp | 2021-05-03 12:22