Line tracing ignores objects and actors

i am trying to set the line trace to set to the center of the screen on every object that is first in the view (or should i make the crosshair follow the line trace?) but no success. If i am shooting an object that is very close, the line trace is way off to the left from the middle, if i am shooting something far away i am less off to the left.






1 Like

you’re hit result is likely correct but you havent updated the trace, so the trace will always END at your Camera forward vector, if you want to update your debug line then OnTraceHit you need a second trace from your muzzle to your HitLocation or if you want to move the Cursor to the HitPoint you’d need to convert WorldLocation To ScreenLocation and update your widget

2 Likes

As above, the script is fine, you will either need to redesign the gun to:

Or:

[…] should i make the crosshair follow the line trace?

Do this If you want it to be somewhat realistic. You can convert trace hit location to screen space with one of these:

2 Likes

I did this and it seem to work, but the projectile starts at the camera not at the barrel. Every time i set the barrel at the starting point the end point changes too. I think I can add a separate projectile after the line trace by channel for a bullet.


how to update the trace please?

if you want to shoot exactly at the crosshair you need 2 separate traces one from Camera to Camera End which you have, and a second trace from the barrel to the CameraHitResult or CameraEnd if no hit.

this will make the gun shoot exactly where the crosshair is, keep in mind you could still get weird results with close objects

2 Likes

Can we see the updated part that spawns the bullet actor?

1 Like

i didnt do it yet :smile: i will upload once i finish. currently i have this

thank you i will try your solution :slight_smile:

thats how it looks atm in game with projectiles shooting from the camera and without bullet from barrel projectile

i tried this set up but it spawns the projectiles to the previous impact point, so if i shot in place they will be appearing after the first shot but if i change where i shoot for each bullet each of them will appear on the previous shooting spot.

you re setting the impact point after spawning the projectile, you need to do it first

2 Likes

thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.