0 votes

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?

in Projects by (63 points)

1 Answer

0 votes

Probably best to use a ray which casts to the mirror, then get the angle of incidence and follow the law of reflection: https://www.youtube.com/watch?v=vt-SG7Pn8UU

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

by (59 points)

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.