Aiming laser that redirects when it hits an object?
I'm creating an aiming system that displays a laser emitting from the player mesh that shows the projected direction a projectile would take show it hit an object and bounce off it. I have created a beam particle who's target will become any object it hits, however I don't want it to end there and instead reflect off in the direction the projectile would bounce. I believe this could potentially be achieved through debug lines, splines and/or beam particle tangents however I don't have much experience with any of the above. Bare in mind I'm creating a networked multiplayer game so the less taxing it is the better, thanks guys :)
TLDR: Want to create aiming laser that bounces off objects. Think of how grenades are thrown in Gears of War.
This is what I currently have:
The formula in Scott's answer is a very efficient way to re-direct a projectile hitting a surface in a new direction, that part is true. But there's a lot of other stuff that's got to happen in the "you just need to make another beam" part of his answer that isnt explained and that formula isnt in blueprint format either.
So let's expand a bit. In order to maintain a total combined beam length of 1000 units per your blueprint, you'll need a short list of things to go get. You'll need:
Using his formula, let's turn the velocity on the left side into "new direction" and the velocities on the right side into "old direction". Using the impact point as "new start point", we can use the new direction to figure out the "new end point" if we also can figure out how much beam is left over. [Note: You should probably test that there is beam length left - meaning the impact happens within 1000 units, otherwise skip all this calculation stuff].
Starting with the old stuff, "old start point" is the tip of your gun. Use a socket on your gun or whatever was fed into the start point for beam #1 here. (Not shown in image). The "old direction" is the direction beam 1 was shot in - again you can use a forward vector on the projectile or gun socket to feed there before the trace. You could also subtract the Trace End from Trace Start too. Just make sure you Normalize that before feeding it to that Dot product node so the pointing direction is a length of 1.
Right, so onto the new stuff. "New start point" is easy - that's the impact point included in the Hit result. "New end point" is a little more complicated. We gotta know which way that beam is going to go, and how much beam is left to extend in that direction, yes?
Let's do the length first because that's based on old things we already know. The Vector Length from your gun to the impact point tells you how much was used in Beam #1. Subtract that from 1000 and you have your "new length" of Beam #2. This is also a handy point to do a branch test because if that length is negative, there's no Beam #2 to be made.
To get "new direction", let's re-write Scott's formula as: NewDir = OldDir - 2 ( OldDir dot ImpactNormal ) ImpactNormal. Note that for a line trace, normal and impact normal give the same thing.
Last step, now you have a unit vector pointing down the path the beam will reflect in, you just need to multiply that by whatever beam is left over and add that result to the impact point in order to determine "new end point". I didn't actually test the BP in the picture so might have some things mixed up there...
answered Jun 21 '16 at 11:06 PM
Cheers guys, I'll test the stuff out as soon as I get to my computer. In regards to physics. They are restricted to movement along the xy plane and are not effected by gravity.
answered Jun 22 '16 at 09:35 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here