Line trace based on reflection (bounce)

I have a shoot mechanic that launches a physics ball that can bounce on the level collision (it is basically the FPS template ball). In relation to this I want to create a preview of the bounce trajectory. The idea is to use the trace to let the player know what direction the ball will bounce, before he actually launches it.

Later I will switch out the trace with a mesh (my “preview line”) and transform it using the values currently passed to the trace’s end-input. Until then I have used the trace to get the basics right.

Obviously there will be an error margin as the trace/line will not care about the physics (velocity and shape). I’m planning to accomodate for the velocity by using the charge values as criterias for the trace length etc. I will add the trace/preview to a tick event once I see that it is acceptable.

As you see in the video: - YouTube

it is not working correctly. It seems like trace #2 is being done from the mesh normal rather than the reflect vector. I guess my math is incorrect here.

My questions are:

1. Any thoughts on why this is not working?

2. Suggestions for better ways to do this? If possible.

Here is my blueprint.

I am by no means an expert… But wouldn’t you be looking for the (impact normal - the angle of you trace ) * -1

This way the angle of reflection will change based on your angle of attack?

sorry I am an idiot… I should have said
impact normal + (impact normal - the angle of you trace )

Hi. The formula should be R = 2*(V dot N)*N - V according to what I have read. See 3D Programming - Weekly : Reflecting a Vector

I attempted to change it to what you wrote, but it didn’t give me correct results unfortunately.

1 Like

Hi potoo,

This isn’t based off of the projectile but instead it’s based directly off of the player view. See if it gives you any ideas. The ‘Mirror Vector by Normal’ might do the trick.

Cheers,

TJ

this code is working for me except it don’t reflect correctly in the -X world direction
In that direction it reacts like the normal is fliped, then instead of reflecting it refracts

I tested this in 4.6.1 but I couldn’t get your results. Which version of the editor are you using? Also, take a look at this tutorial I posted just to make sure everything is the same.

I’m using 4.6.1.
actually the problem is when the line trace hits a normal in 1,0,0 direction ( it not about the world)
But I’ve made a reflection by normal that is working for me (it was a hell to do this since I’m not a programmer)
I think is a bug because I saw other users reporting the same problem.
below the code:

I’m glad your custom function got this working for you. If you have time could you try this function instead and let me know if it also works correctly or if you experience the error again?

Hi! I’ve tested it and (I think) the behavior was the same of the default “mirror vector by normal” node. the error persists.
this setup was the same I did, only inverted the order of the multiply.

I don’t know why but when it calculates against the 1,0,0 normal it refracts so I multiply to -2 instead of 2

Edit: I tested and the setup I made didn’t worked in other conditions (different position) this is making me crazy
maybe if I make a video showing the problem you can helpme?

I know you’re in 4.6.1 now, but did you upgrade your project from an older version of the editor? The reason I ask is on further testing, my original setup works correctly in a new 4.6.1 project but I noticed that I get the same results as you in a older 4.5.1 project I have.

I don’t remember really well but maybe even before 4.5.1.

thank you so much for testing that you are awesome.

there’s any way to fix this?

Okay, here are a couple possible solutions. Both fixed the issue for me in 4.6 but not 4.5.

Add the Normal and Impact Normal of the previous line trace and use that info to set the Start of the next line trace.
28166-
Or make an Array out of the Hit Actor and have the next line trace ignore that actor.
28167-
Let me know how they go.

I’ve also logged this as JIRA UE-8434 in our tracking software. So our devs will be looking into this issue as well.

I tested booth solutions. but still it has the same problem.
very odd…
thanks for submitting this for fix

I’ll try again when I got home. I’m thinking… maybe it stopped working because I put the results of the line trace to a variable and traced the next line with the variable.
I really have the impression that when I first tested the tjballard solution it have worked

Same here. I think we have the same issue/bug.

I’m considering moving the project to a fresh 4.6 version to see if it resolves it. My current project has been upgraded a couple of times (from 4.3 i think) and is now 4.6.

I will also try gustavorios2’s workaround.

Thanks for all the replies/help so far!

The JIRA report came back as not being a bug. The developers said that the correct way to handle this setup is to use the first fix I posted above. You shouldn’t directly line trace off a a surface normal, you need to add that small offset to keep errors from happening.

However, there still seems to be issues with older converted projects. I believe recreating them in 4.6 will fix the issue and upgrading from there works correctly (tested with our latest internal build).

Here is a tutorial I posted with those changes.

On a new empty project everything works fine though…
I tried to create a new project and copy the game folder from the older project to the new but the line trace problem came with it

Since it’s only a few nodes. What if you remove the ricochet blueprint setup from the old project, migrate the content, then recreate the ricochet blueprints again in the new project?