# How to line trace in between previous frame and current frame?

**URL:** <https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [May 13, 2024, 8:50pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582 "2024-05-13T20:50:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 13, 2024, 8:50pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/1 "2024-05-13T20:50:09Z")

</div>

I cast a line trace from my camera every frame to hit actors, and i want to make sure that on the next frame i can have captured anything between the new line trace position and the line trace position on the previous frame. The effect I’m after is like a sweep to make sure nothing is uncaught between frames.

---

<div class="post-metadata">

**Author:** ![Midisport\_8x8s](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Midisport\_8x8s](https://forums.unrealengine.com/u/Midisport_8x8s)\
**Post date:** [May 13, 2024, 8:50pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/2 "2024-05-13T20:50:38Z")

</div>

Save a variable one frame and read it the next.

---

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 13, 2024, 8:52pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/3 "2024-05-13T20:52:56Z")

</div>

I don’t understand. How can I check the distance in between?

---

<div class="post-metadata">

**Author:** ![Frenetic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/frenetic/32/1142542_2.png) [@Frenetic](https://forums.unrealengine.com/u/Frenetic)\
**Post date:** [May 13, 2024, 8:54pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/4 "2024-05-13T20:54:50Z")

</div>

when you run the first line-trace capture the points on either end, so you can read them the next trace.

You can use distance or vector length between any of the points to calc lines/distance as you need.

---

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 13, 2024, 9:03pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/5 "2024-05-13T21:03:18Z")

</div>

Thank you I think that makes sense, but if I’m in first person and casting a line trace from the camera then the distance of actors i’m tracing for could be at any distance away from the camera, so tracing between the different cast points would not guarantee capturing those in between actors at any distance, right?

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 13, 2024, 9:03pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/6 "2024-05-13T21:03:19Z")

</div>

Store the first trace hit location to a variable(it’s the last frame hit location),fire another line trace,starts from first trace hit location to the location you stored.

---

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 13, 2024, 9:05pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/7 "2024-05-13T21:05:48Z")

</div>

But what if the actor in between those two places is not on a direct trajectory between them since they’re not all at equal distance away from the start of the line traces (first person camera)

---

<div class="post-metadata">

**Author:** ![baobao4435](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/baobao4435/32/950790_2.png) [@baobao4435](https://forums.unrealengine.com/u/baobao4435)\
**Post date:** [May 13, 2024, 9:28pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/8 "2024-05-13T21:28:17Z")

</div>

> [@Jsqueeze](#):
>
> what if the actor in between those two places is not on a direct trajectory

I don’t know,but I would give you some info how they make melee combat game.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/2/6a27625d4aaf1fa62ccd496e27bec7cb6e920e3b.jpeg)  
They have multiple line traces from last frame to current frame like this.i don’t have real experience though.  
you could see if you could pick some ideas from it ,modify a little and take to the project 🙂

---

<div class="post-metadata">

**Author:** ![Frenetic](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/frenetic/32/1142542_2.png) [@Frenetic](https://forums.unrealengine.com/u/Frenetic)\
**Post date:** [May 13, 2024, 9:37pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/9 "2024-05-13T21:37:44Z")

</div>

With regards to the line-traces, what are you ultimately trying to do? There might be free(ish) things that already do this better, and quicker, than you or I.

eg: [https://www.unrealengine.com/marketplace/en-US/product/rama-s-melee-weapon-plugin](https://www.unrealengine.com/marketplace/en-US/product/rama-s-melee-weapon-plugin)

---

<div class="post-metadata">

**Author:** ![Shmoopy1701](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shmoopy1701/32/1194536_2.png) [@Shmoopy1701](https://forums.unrealengine.com/u/Shmoopy1701)\
**Post date:** [May 14, 2024, 12:31am UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/10 "2024-05-14T00:31:22Z")

</div>

First pass for me would be something like:

- take line from this trace and previous trace
- calculate a quad or box out of both lines
- whatever the quad intersects was hit

---

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 15, 2024, 9:08pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/11 "2024-05-15T21:08:27Z")

</div>

Thank you, yes I had considered some sort of box or converting world space to screen space maybe, but i’m not learned how to do either yet.

---

<div class="post-metadata">

**Author:** ![Jsqueeze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jsqueeze](https://forums.unrealengine.com/u/Jsqueeze)\
**Post date:** [May 15, 2024, 9:10pm UTC](https://forums.unrealengine.com/t/how-to-line-trace-in-between-previous-frame-and-current-frame/1854582/12 "2024-05-15T21:10:18Z")

</div>

thank you for the effort!
