How can i make a 2D light beam bounce/be reflected by mirrors?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Anastasia

I’m working on a puzzle game based on a light beam thet gets reflected in mirrors. It looks like a white line. My problem is how can i make it reflect in mirrors when it touches them?
This is what i’m trying to achieve:
Visual representation

What im thinking is making an area 2d that detects when it touches a mirror and triggers a function in its script that will once again instanciate the light beam scene. But how will it get the corect rotation? how do i make it stop when it reaches an obsacle?

:bust_in_silhouette: Reply From: Sean

Probably best to use a ray which casts to the mirror, then get the angle of incidence and follow the law of reflection:

If you do this you will need to cast a new ray with each bounce.

Hi, thank you! i know how reflections work, i studied them in physics class!
Problem is i dont quite know how to do that. in the engine.
Thank you still for your answer!

Anastasia | 2020-04-24 12:49