- Home /
Clipping everything inside a shape
I'm wondering if it's possible to clip everything inside some invisible shape?
For example if if a cylinder shape was used between a 3rd person camera and the character. Anything that got in between the camera and the character would be 'pierced' by the cylinder and the camera would see through the hole to the player/terrain/etc.
I've done a bunch of searches and found some 'clipping plane' topics, but it doesn't really do what I'm looking for. (Simple Cross Section Shader)
Answer by Waz · Sep 08, 2011 at 11:47 AM
No, there isn't. But there are many other solutions to the third-person player occlusion problem. None perfect, but likely all better than that would look even if it could be done, though I applaud you for trying to think of new solutions... maybe one such will be perfect.
Yeah, I'm just trying to avoid moving the camera around. It's fairly stationary and always faces the same direction on a 45degree angle. I figured some kinda clipping thing might work like far and near clipping planes for cameras, only for a specific area.
The walls are made of mesh blocks so in a different attempt I just raycasted from player to camera and made the blocks in between transparent, but I have to use the combine children script to keep up performance. Which means I can't make them individually transparent anymore. Guess I'll have to try another approach. Thanks anyway.
A common solution with a fixed camera is to use level design to ensure no occlusion. Eg. put lower walls, trellis/lattice, or glass everywhere that there would be a problem.
Answer by sydan · Sep 08, 2011 at 12:27 PM
A possible solution is to have two cameras:
Camera 1 is your normal camera, this views the whole scene as you would expect, however it also runs a raycast from the camera to the player. If anything gets in between the camera and the player it activates camera 2.
Camera 2 sits in exactly the same place as camera 1 and views the player in the same way, however it doesn't view the whole scene. It's culling mask is just the player. In this way, provided Camera 2 is above Camera 1 in depth and has a transparent background, you will always be able to see the player, even if something moves between the camera and player.
I haven't tried this, but it's an idea that popped into my head a few days back... possibly worth a try.
Ugh. I just had to make a new account to comment on this... because for some reason UnityAnswers uses case-sensity usernames... anyway. I'll reply to any comments on this account.
Hmmm yeah thanks this does sound interesting. I'll try it out tomorrow, if I can think of a way to display the player differently when he is not in the view of camera 1 because of obstructions it could work out nicely. I'm thinking raycast again.
Tried it out, it worked but the player was displayed ontop of everything.. Walls, items, etc. I thought about making everything display infront of walls so that wouldn't happen but then of course you'd be able to see all the items on the map from anywhere..
This is probably as close as I am going to get, I may just have to change the camera angle ins$$anonymous$$d.