Mirroring lasers, and breaking at collision


Dear CommUNITY,

I have been brain crunching with this for some time now, and tried a few different approaches and failed, so I’m hoping that some of you can point me into the right direction.

I’m trying to setup the base mechanic of the game, which is shooting and combining lasers together.
The idea is, there’s a player, you shoot a laser, and if someone points his laser through yours, you will combine your powers to a more powerful laser.

The other thing, is that the laser should mirror bounce off of walls, and continue until reached it’s maximum length. Now im sure you would have to do something with normals there, but how to get it to work…

I have now a setup where the laser is a line of 24 cubes, connected to eachother, all with same parent. I scale the parent to increase the length of the laser, and as they all 24 have their own id, if ID 16 gets hit by some corner, all upper id blocks disappear. But I think this setup is as buggy as hell, and just a work around!

So I would so love to see some idea to get this to work! Thanks in advance!

nobody?

You definitely should not use a line of cubes for the laser. Instead, you should use Rays and vector math. A Ray is a nothing more than a line with an origin and a direction, and you can get points along its length - exactly what you need for your laser set up.

Using Physics.Raycast, you can determine if you hit a wall. The RaycastHit you get from a hit also gives you the normal. You can then use that normal to reflect the laser off the wall using Vector3.Reflect.

You can use different methods to then visualize the laser - LineRenderer is one of those that should be easy to get started with, but definitely not the best looking one.