# Line trace based on reflection (bounce)

**URL:** <https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286>\
**Category:** Rendering\
**Tags:** line-trace, reflection, bounce, unreal-engine, question\
**Created:** [January 18, 2015, 1:52pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286 "2015-01-18T13:52:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GreasyExcretion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GreasyExcretion](https://forums.unrealengine.com/u/GreasyExcretion)\
**Post date:** [January 18, 2015, 1:52pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/1 "2015-01-18T13:52:29Z")

</div>

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](https://www.youtube.com/watch?v=pIM19IINkCA)

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.

 ![27066-blueprint_reflect2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/5/c75a169cad6345aa4582b908fae7e75d73f0d029.png)

---

<div class="post-metadata">

**Author:** ![Hexmare](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hexmare](https://forums.unrealengine.com/u/Hexmare)\
**Post date:** [January 18, 2015, 5:37pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/2 "2015-01-18T17:37:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hexmare](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hexmare](https://forums.unrealengine.com/u/Hexmare)\
**Post date:** [January 18, 2015, 5:48pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/3 "2015-01-18T17:48:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GreasyExcretion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GreasyExcretion](https://forums.unrealengine.com/u/GreasyExcretion)\
**Post date:** [January 21, 2015, 2:57pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/4 "2015-01-21T14:57:06Z")

</div>

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](http://www.3dkingdoms.com/weekly/weekly.php?a=2)

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

Thanks for reply!

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 21, 2015, 8:30pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/5 "2015-01-21T20:30:57Z")

</div>

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.

 ![27478-ricochet01.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/2/5229ecc2404379c9665d71fc151428246825c58e.jpeg)

Cheers,

TJ

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 25, 2015, 2:35am UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/6 "2015-01-25T02:35:02Z")

</div>

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

 ![27851-243535345454.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/2/8824643d4ecc0362f0a69366dcddf5bb0f46742d.jpeg)

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 26, 2015, 7:50pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/7 "2015-01-26T19:50:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 26, 2015, 8:33pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/8 "2015-01-26T20:33:01Z")

</div>

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:

 ![28005-2313441123.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/8/8e85cd836eec9b928d0b572326e91c43df1087db.png)

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 26, 2015, 9:42pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/9 "2015-01-26T21:42:54Z")

</div>

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?

 ![28015-custommirrorvectorbynormalfunction.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/d/7/2d7f9b1d76fe44c2e156221085cfc7dd492565e9.jpeg)

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 26, 2015, 10:56pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/10 "2015-01-26T22:56:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 27, 2015, 2:26pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/11 "2015-01-27T14:26:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 27, 2015, 2:30pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/12 "2015-01-27T14:30:28Z")

</div>

yes! I upgraded many times…  
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?

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 27, 2015, 10:06pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/13 "2015-01-27T22:06:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 27, 2015, 10:46pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/14 "2015-01-27T22:46:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 28, 2015, 11:56pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/15 "2015-01-28T23:56:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GreasyExcretion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GreasyExcretion](https://forums.unrealengine.com/u/GreasyExcretion)\
**Post date:** [January 29, 2015, 11:25am UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/16 "2015-01-29T11:25:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 29, 2015, 1:07pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/17 "2015-01-29T13:07:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 29, 2015, 3:29pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/18 "2015-01-29T15:29:38Z")

</div>

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.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![gustavorios2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gustavorios2/32/1194641_2.png) [@gustavorios2](https://forums.unrealengine.com/u/gustavorios2)\
**Post date:** [January 29, 2015, 3:34pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/19 "2015-01-29T15:34:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [January 29, 2015, 6:02pm UTC](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286/20 "2015-01-29T18:02:37Z")

</div>

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?

[Next page](https://forums.unrealengine.com/t/line-trace-based-on-reflection-bounce/304286.md?page=2)
