I am trying to create a beam effect where all targets inside the beam take damage. However, I’m having trouble getting it to line up with the beams position. Should I use a collider instead? The beam’s width and length is dyanmic so I will need to adjust it with code.
In hindsight, there’s no ‘LinecastAll’ method, so perhaps not very useful. There is a BoxcastAll though.
For the box cast, it’s pretty simple to work out the parameters you need. You just need to know the center position - which is the start position + half the direction to the end position - and the the ‘half-extends’, which is just half of what will be the overall size of the box. The length is similar to before, half the direction/distance to the end point. And then the width and height are just half whatever size you want to define.
Using a trigger collider is an option. Performance is probably negligible. You’d have to measure that (but only if you are experiencing performance issues).
In either case you will still need to work out the position and size of the box. But the same logic I have above should work for both of them, except in the box collider you need to work out a rotation based on the direction, rather than just a direction.