SebLague / Portals

Portals in Unity
https://www.youtube.com/watch?v=cWpFZbjtSQg
MIT License
773 stars 167 forks source link

How could I implement a flashlight that works with the portals? #21

Open NicolasRisso opened 1 year ago

NicolasRisso commented 1 year ago

The idea is basically to make the light that gets out of the flashlight pass through the portal, or simply make the cameras in the other side of the portal have their own flashlight to give the illusion of light passage (I particularly tried this one and didn't got a smooth result , cause probably by the portal camera stoping their movement if the player is looking the portal from the sideways or looking at it's corners).

kaitabuchi314 commented 10 months ago

Hello! If you are using lights to make a flashlight, you could make 2 lights, one for the flashlight and one coming out the other portal, pointed in a certain direction based on the original direction. I'm not very good at math, but maybe we can map the position the light hits on the portal to the other portal, then imagine if the player was there and his rotation was his original rotation but with the difference of the rotation between the forward direction of the portals added, then the new light rotation and position is the position and rotation of the hypothetical player. But don't trust that math, I don't know what the correct math is.

kaitabuchi314 commented 10 months ago

Sorry for not reading your full issue!

kaitabuchi314 commented 10 months ago

Can you please provide an image (not a YouTube video)?

NicolasRisso commented 10 months ago

Sure thing! I tried adding the lights to the portal camera too, but it had 2 main problems:

  1. In the border of the portal, for some reason, the camera stoped moving accordingly with the player camera (image) (image2)
  2. Some parts of the map are really close, and, since my map is dark, sometimes the lights that the portal renders in the other side is visuable. I know that level design can fix that, but I think it's an relevant point too.

I think that the portalCam probably stop moving when you look to close to the edge, maybe some fancy code could fix that, but I still think that a shader would be nicer.

imagem_2023-09-20_142906193