# How can I fix the linetrace to shoot at the location pointed by the CrossHair

**URL:** <https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [March 11, 2022, 11:57am UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976 "2022-03-11T11:57:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PAULASTYA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/paulastya/32/266396_2.png) [@PAULASTYA](https://forums.unrealengine.com/u/PAULASTYA)\
**Post date:** [March 11, 2022, 11:57am UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/1 "2022-03-11T11:57:13Z")

</div>

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/9/1/a9171cb407637c0a76494e59ca863c455c11a794.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/9/1/a9171cb407637c0a76494e59ca863c455c11a794.mp4)
  
The link to the CrossHair bp:[DynamicCrossHair.uasset - Google Drive](https://drive.google.com/file/d/1KhEKZhgG1uzuEGFKkF9BXkVA_fIhRm71/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 11, 2022, 11:57am UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/2 "2022-03-11T11:57:56Z")

</div>

Can you show your linetrace code?

---

<div class="post-metadata">

**Author:** ![PAULASTYA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/paulastya/32/266396_2.png) [@PAULASTYA](https://forums.unrealengine.com/u/PAULASTYA)\
**Post date:** [March 11, 2022, 12:03pm UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/3 "2022-03-11T12:03:03Z")

</div>

![Screenshot 2022-03-11 173126](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/4/c/c4c5a3d1abd8bfeaae9383e6917596e29167f35c.jpeg)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 11, 2022, 12:07pm UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/4 "2022-03-11T12:07:25Z")

</div>

Right. The problem is your crosshair is firmly screen center. Which means a normal camera trace is needed.

If you want to trace from the gun, I think you have to do the whole thing from gun, and move your crosshair around dynamically.

---

<div class="post-metadata">

**Author:** ![illYay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@illYay](https://forums.unrealengine.com/u/illYay)\
**Post date:** [March 11, 2022, 10:29pm UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/5 "2022-03-11T22:29:41Z")

</div>

Normally GetActorEyesViewpoint gets you the camera position and direction. It might not be exactly right in third person so I’d double check, but usually it uses the camera components as a source if they exist. If not, use the camera component’s position and direction instead of GetActorEyesViewpoint.

And you can use that as the source of the linetrace.

It does look like you’re using a camera vector of some sort, not sure if that’s a reference to the actual camera you’re looking through. It should work though normally.

That would give the position the crosshair is aiming at, and then you can make your gun fire a bullet from where the barrel is to where the crosshair is.

It may not be 100% accurate since that’s not literally where the gun is facing but it’ll feel right to the player.

In fact most games do something like this, and no one notices, especially if it’s a hitscan trace.

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [March 11, 2022, 10:35pm UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/6 "2022-03-11T22:35:22Z")

</div>

Check the “DeprojectScreenToWorld” node from the GameplayStatics library

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [March 11, 2022, 10:37pm UTC](https://forums.unrealengine.com/t/how-can-i-fix-the-linetrace-to-shoot-at-the-location-pointed-by-the-crosshair/505976/7 "2022-03-11T22:37:31Z")

</div>

> [@illYay](#):
>
> It may not be 100% accurate since that’s not literally where the gun is facing but it’ll feel right to the player.
> 
> In fact most games do something like this, and no one notices, especially if it’s a hitscan trace.

This is correct, as you’d otherwise require complex IK solutions for the gun’s barrel rotation. \*_Edit_ not that this is bad but it is usually unneccesary. I like to do this when simulating realistic recoil or animation based weapon actions. In many non realistic games you won’t need this.
