- Home /
Can Layer Masks Achieve This Effect
If you look at the image below you will see the player surrounded by a dotted yellow box.
![example][1]
The dotted yellow box is also part of the player and represented a portion of the player being masked from both rendering and affected by physics. My question is if layer masks in Unity can achieve the following effect.
-In Area 1, the red box/animations of the player are visible and the rigidbody of this shape is affected by all Physics.
-Any portion of the player that enters Area 2 makes the larger yellow box within the area become visible (and affected by physics) and vice versa for any portion of the smaller red box that enters.
-This can persist when both entering and leaving either area from any direction.
Thank you for any help! [1]: /storage/temp/31386-mt2wh.png
You might be able to do the visual part by using the stencil buffer. Look here: http://answers.unity3d.com/questions/590800/how-to-cullrender-to-through-a-window.html
And for the physics portal effect, maybe here (not sure it helps): http://answers.unity3d.com/questions/60709/portal-physics-effect.html
@supernat I tried your technique you mentioned with stencil buffers and it did not work.. I am asking a new question which includes the source for my shaders. I'll link that to you once my question is approved.
Answer by Pyrian · Aug 23, 2014 at 07:00 AM
Okay, first the physics layers. You'll just need two, I'll call them "Redbox" and "Yellowbox". You'll set them to collide with themselves, and not each other. Then, set the red box itself and any colliders in area 1 to Redbox Layer, and the yellow box itself and any colliders in area 2 to the Yellowbox Layer.
That's probably the easy part. Sorting Layers will be slightly more annoying. You've got to make that yellow box draw BEHIND the BACKGROUND in area 1. And the background in area 2 needs to be even further back. So, they can't be the same background, you'll have to divide it.
Your answer
Follow this Question
Related Questions
LayerMask is incorrect 1 Answer
Using unity 4.6 UI and raycast2D functionality 0 Answers
Raycast Layermask doesn't ignore no layered Parent? 1 Answer
Physics Collision Layer Programmatically. 0 Answers
How to mask sprites in 4.3? 2 Answers