Search code examples
game-developmentgodotmaskinggdscriptculling

How would I hide an object from a specific camera in Godot 3D?


I'm working on a multiplayer horror game in Godot and I want to make it so you can't see your own body but others can. I heard about culling masks for this but I have no idea how they work and if what I'm trying to achieve is possible using them. The body is a Skeleton node and others should be able to see it but my camera (a sibling of the skeleton node) shouldn't be able to. Could someone explain how I might be able to do this?


Solution

  • The Skeleton is not visible. However, you must have some children VisualInstances (usually MeshInstance) which are actually visible.

    In the usual setup, you have a Skeleton node, with multiple MeshInstance as children, which also have their skeleton property set to the Skeleton node.


    I don't know how you are setting up your multiplayer, but if it is not split-screen you probably can swap or remove the player character but not those of the other players. If removing the Skeleton is not viable, you should still be able to remove or hide its children VisualInstances.


    Anyway, if you do need to setup multiple cameras, you can se the layers on the MeshInstance (or whatever VisualInstance you are using) and the cull_mask on the Camera. If they overlap (they have common bit flags) then the Camera will render that MeshInstance, otherwise it wont.

    See also Hide an object for a specific camera.