Changing Length of Laser Beam on Collision?

Hello there!
I’m trying to improve the concept explained in this tutorial. The difference between the tutorial’s laser beam and my idea is that my lasers’ lengths would change when they come into contact with a physics object. This would allow objects to be used to block out the beam. When the tutorial lasers spawn, their length is set. If anything gets in their way, or what was once in their way is moved, their length remains the same.

I added this

to the tutorial blueprint so that when a piece of furniture overlaps with the box, it does another line trace, and the location the trace hits (in this case, the table) becomes the new beam end point. Instead, the beam created goes in a completely different direction, as shown:

I ran an experiment to see if the line trace hit other objects when the table entered the box (shown as the wireframe), and the line trace hit any object except the table which triggers the trace itself. When the trace actually does hit something, the laser length changes as expected. The table is an actor blueprint, which may have something to do with it. How can I make the line trace notice my table?

Hi there. There’s a couple of things I would try:

  1. If you’re already using a line trace to get the original endpoint of the beam, I would attach a branch node to the return value of the trace that will return true if there is a hit. From there you can set the Beam end point to the Impact Point vector from the hit result. The impact point will return the exact vector that the trace hits, rather than the location of the hit actor (I could be mistaken but I believe that the Location pin returns this.) If Blocking Hit returns false, you can set the end point to the original location. This would eliminate the need for the overlapping box and allow you to place any object with collision in the lasers path to block it. If you want the end point to change only when it hits a specific object like the table, you cast to it from the hit actor pin.

  1. With your current setup, the only thing I guess is going wrong is maybe that the table mesh is not at a relative position of zero. Is it offset from its root component? Try setting from the impact point and see if that makes a difference.

Anyway, hope this helps!

That helped a whole lot. The laser’s length is affected by props now. Thanks for the quick reply! I tested your idea out, and I think the line trace will work to solve the problem. If you have a little more time to help, the solution raises a few more problems. Here’s the real troubling one:

As I said, the laser’s length is affected by props.

When I move the television away from the beam, its length does increase.

I haven’t done the programming for the wireframe box yet, but don’t worry about it. As you said, I might not need it. The problem now is that whatever length the laser is when it is spawned is the laser’s minimum distance. Does your laser do this? If so, how would you set the laser so that its minimum length is 0?

Happy to help. I’m not sure what’s going on there, because it’s almost as if its ignoring the collision of the television if its overlapping the box. Not sure what it possibly be doing if it;s working outside of those bounds. I threw something together just now to see if I could replicate it, but it seems to be working fine. If you using a cascade particle system like I am, this set up should get you what you’re looking for. (Unless it’s only working on my end :P)

Again, I’m not sure what your set up looks like, but for me it produces this result:

210530-ue4editor-2017-08-20-16-06-36.png

As you can see, I’m able to move the prop very close and across the room, and I’ve tested position in between successfully. This works with both static mesh actors and blueprint actors, so long as they have a mesh with collision. I hope this get you in the right direction!

Cheers!

Congratulations, you saved my entire game!

Can’t thank you enough. One quick question- could I see your laser’s particle system? It’s less blindingly bright than mine, which is good. You’ve done good. Thank you again.

Sure thing. It’s just a simple gradient I threw together in photoshop. I’ll have to see if I have the original texture anywhere, as I’ve been just migrating from old projects. I’ll link the .uassets here, you should be able to unzip it into your content folder. If there are any issues, I can send you the entire project I made earlier, so you can migrate manually.

I am trying to use this function on my motion controller and my laser just goes through collision no matter what, and its always the same size. I am updating my beam source point on event tick since the controller is always moving. Any ideas? Completely lost at this point I have tried what I know.

Hey Drkephrim,
Would you mind sending me the project having a hard time putting this together with a motion controller. Would help out a lot!
Thanks.