- Home /
Is there any way to hide only part of an object from the camera? (unity free)
I have a Virtual Reality scene in which you can see your own characters body. However, the character's face can sometimes be seen through the main camera (mainly when looking downward). This character is a whole model, so limbs, head, etc. aren't separate. Therefore I can't use layers to hide the character's head from the camera. And moving the camera outside the model distorts the view of your character model in an immersion-breaking way. Is there any way I can hide the character's head from the main camera?
Answer by IgorAherne · Jun 07, 2016 at 11:36 PM
Hacky way, but unless you want to start fiddling with mesh vertex colors in blender/3ds max (to use them to discard fragments in your shader), do the following:
just use transparent cutout shader and make sure the head's part of the texture is transparent. This will mean you'll have problems when looking in the mirror though.
Answer by izukingz · Mar 30, 2019 at 01:06 AM
@Vigil1
I know this is 3 yrs now but I ran into this issue and this is the only place i've seen it discussed. This is how I just solved it. First of all I made the camera rotation to rotate the neck of the character only in the x and y direction.
//Camera script
neck.transform.rotate = Quanterion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, neck.eulerAngles.z);
This makes when you look up/down and left/right in the VR, the character neck/head will follow your movement.
The above does not fully solve my issue as you may have noticed. When you look down, the camera rotates in place while the head moves downwards, thereby blocking the camera view. I thought about solutions like clipping the near distance of the camera which is not ideal.
Then i came up with a solution to create an empty object as child of the head and place it just in front of the eyes of the character.
I then map the position of the camera to be the position of this object. Since when the head starts rotating downwards, the object position will change. This will cause the camera position to follow it in turn.
transform.position = object.position;
Hope this helps any other person
Your answer
Follow this Question
Related Questions
occlusion culling conflict with shader,Occlusion culling conflict with shader 0 Answers
UI masking in a jet fighter HUD 0 Answers
Exclude layer from culling 1 Answer
Invisible effect? 3 Answers
Hiding parts of a mesh 1 Answer