Trying to Line Trace a projectile from the muzzle of my gun to my center reticle



I’m losing my mind trying to figure out what to do to fix this.
I cannot get this blueprint to work in multiplayer no matter what I try to do. It’s a multicast event, both characters properly call it, but the issue is simple:

The line trace for the camera only ever follows the server’s camera. The client will shoot from the muzzle, but no matter what the muzzle linetrace always follows the server’s camera. I’m trying to use a listen server for this.

Does anyone have any ideas? I’ve been stuck on this for a good four hours now and I’m tearing out my hair. If this were a singleplayer came it would work fine, but the multiplayer replication is driving me insane. I’d love an explanation and a way to make it work if possible!

Thank you.

check out MizzoFrizzo’s (Pitchfork Academy) True FPS Shooter YouTube series on this.

you can do something like this: but use my end point and use his staring point. (mine fires from center of camera to center of screen) and just use his start point of gun barrel rather than center of camera. You need to pass a replicated variable of type transform from client to server. So from IA_Fire, whenever you’re ready to fire the weapon, get the camera actor and get world transform, and pass that to your server event.

Instead of using this transform location as the start point, use your weapons barrel socket.

The video method will fire and end wherever the gun is pointing, so you need to align scoket and/or animation to make sure it hits the center.

I do find making it fire from the center of the camera as I do here is better for a fps game like csgo and not a true fps., passing through camera transform, getting its rotation, getting its forward vector and then multiply it by single precision(float), you can type something like 10000 if you dont have a range variable, then make sure you add that to the location and use that as the endpoint. Hope this helps clear anything up!

I think you’re on the right track here, line trace should be fired on server and your weapon animations need to be multicast. Fire button pressed, set canfire, do firing logic, call to server, do line trace, call multicast, do animations, fire button released, set canfire false.

Keep in mind, your clients wont actually replicate the line trace on screen and they wont see the server casting it, only the server will see the debug draw, but it will work.

Will this work for multiplayer?
Because even my current code works fine on the server, but the client does not work. That’s the issue I’m running into right now.

Edit: I should mention this is a third person shooter as well.

1 Like

Yes, i made an edit to explain why you wont see the client casting it, because it only needs to happen on the server, this way clients cannot cheat in a way.

this is the server spectating the client, does your server see the client casting it?

edit: try this logic out on your side, but use the thirdpersoncamera or follow camera instead just to see if you can get it firing, then adjust your start point to your barrel socket. if you play as client you wont see the debug on your screen and clients wont see server doing it but server will see client doing it and you k now its working.

Yeah right now this is what it looks like. See how on the server’s side it’s going to the server’s crosshair and it’s also visible on both?

1 Like

okay, i think it’s working, there just seems to be an issue using follow camera cause all players use that. now try making it your gun barrel socket as the start point. Your server shouldn’t be replicating the trace to the clients, the clients only ask if they can fire a trace on the server.

Yeah it starts from both of the gun barrels, but the clent’s line trace always ends at specifically the location the server is looking - and on the client’s end, the servers line trace ends where the client is looking no matter which client or server is shooting.

That’s the big issue I’m having. It could be I’m not replicating something properly, but I think it’s that I’m somehow not getting the proper camera for each individual player to actually do the end of their linecasts from.

I’m not really sure and I’ve been trying to do this for like 5 hours. The line traces and projectiels are multicasted right now, the shoot event is an event which calls this fireprojectile multicasted event after calling a server event for “primary attack” (which is shooting in this case.)

1 Like

That channel also has a video something like “create your first multiplayer game” and its third person, and somewhere in there he makes the weapon fire from the gun to wherever youre aiming or the crosshair, which might be better suited for third person game. but I am also new to this stuff and I’m not sure if this method only works only for hitscan or not. https://www.youtube.com/watch?v=Dtam3Psxqjc it should be linked in this short. Check this out about an hour in where he does the line trace.

I think part of the issue might be that I’m multicasting the line traces, but even then that wouldn’t really fix the fact that the line traces aren’t following the proper character’s cameras on the server itself I don’t think?

I don’t know, I’m just at a loss at this point. Gonna mess around a bit more and wait to see if anything here helps me or if other people see this post and chime in.

I’ll keep everyone updated.

1 Like

well if you multicast the line traces, that would explain why the client also fire its own line trace when the server does. you only do this on the server if you are the client.

That doesn’t explain why the client fires the line trace at the SERVER’S camera though. It follows the server’s crosshair instead of it’s own on the server’s screen.

If the server aims at a “zombie” for example, the client would be hitting the zombie. If the server doesn’t aim at the zombie, the client literally cannot hit the zombie and instead the line trace fires to wherever the server is looking. That’s the issue I’m having currently.

1 Like

you need to have your client call to the server and run the line trace on the server only. and only the client pressing l click should be calling the line trace. your issue being that you’re multicasting it so the client also does it, and you might be using a reference to the camera that belongs to the server. nobody else should be firing line traces on the server but the client that is clicking.

1 Like

I see, alright I’ll mess around and move some blueprints to the server specifically before it calls the multicast and I’ll see if I can do that.

So you’d recommend calling the line traces specifically on the server, then multicasting the projectiles/animations as stated above? Sorry about the repeated questions, like you I’m also new to this.

1 Like

I am not familiar with using projectiles but yes i would assume you just need to spawn the projectiles on the server making sure the projectile actor is replicated and all clients should see them, since those are spawned into the world that everyone sees. I could be wrong but I don’t think that part needs to be multicast either. I think only the animations, sounds, fx etc. on the weapon itself need to be multicast. Client handles input and like how the fire modes work, then calls to server, run line traces and then spawn projectiles on server, then call multicast where you’d do the animations of the gun.

edit from chat gpt:
Spawn the projectile once on the server and make the projectile actor replicate; don’t use a Multicast to spawn it.

1 Like

Moved all my logic around, same issue - both characters keep line tracing to the wrong camera (in this case the client to the server and vice aversa.)

Only thing I really “fixed” was that now it’s not multicasting the line trace, it’s all handled server-side now. But when the client shoots, it still goes to wherever the server’s crosshair is looking. I definitely think this is an issue with getting the proper camera for the center line trace, but I’m not sure how to fix it.

1 Like

Yeah, i’m not exactly sure on that end point when it comes to the third person follow camera because it works with the fps camera.

I linked that tutorial because I am almost certain he makes the endpoint the center of his crosshair, but it might’ve taken some tweaking. I had this same issue too when making my line trace. I’m sure there is some type of tutorial out there or even chat gpt has helped me a lot to understand things, and it does understand UE5 blueprint logic as well.

Sorry I couldn’t be her more help, I have mainly been working on fps projects.

Couple of things to wrap your head around here.

  1. Camera Components do not get updated on the Server or Simulated Proxies. Data is replicated, but the component itself is not updated.

    e.g. Client looks down, so the camera pitch is changed. The new Pitch is sent to the server and replicated to all sims, but the servers and sims cameras do not rotate the component to match the new value.

You have to use Base Aim Rotation. Furthermore, for Camera Location on Server and Sims you have to use the camera manager.

From Controller (or Reference): Get Camera Manager → Get Camera Location

Take crouching for example. On the crouching client (Autonomous) the camera will move with the mesh… socketed to head bone. On the Server and Sims it does not. It sits at its default “relative” location.

Example… Head socketed camera. Purple is Server, Red is Client (Autonomous).


Using the Correct data… Base Aim Rotation && Camera Manager :: Camera Location


Getting the data without references via BP Interfaces…

Component Attached to Pawn (Character)… Gun, interaction system etc.

Character class…

No Casting or Hard References are ever needed if you utilize BP Interfaces and base class nodes.


  1. Proper Multiplayer shooting utilizes a Client Fakey - Server Auth approach that simply passes minimal data. Each proxy (Autonomous, Server, Sim) does it’s very own thing to simulate the shot.

The Clients shot is only there for responsiveness and FX. Server’s handles dmg and never replicates. Sims uses simple data from the server to approximate a recreation.


  1. Client and Server do their own independent traces based on where camera and mesh are at the time of execution.

My project uses projectiles. The following code gets a vector location down range inline with the camera. What you are aiming at… Trace Select Vector.

For ADS you only need a little math. For hip firing a trace is needed.

From there you set the Aim Vector and Aim Velocity. The velocity value is what is applied to the projectile which is spawned or obj pooled from the Muzzle location.

For Hit Scan
Trace Start (Muzzle Location)
Trace End (Trace Select Vector)… using the snippet below

1 Like

I see, alright I’ll give this a shot once I’m back to fine-tuning my actual shooting again.

I finally did it on my own but even when I was making the code I knew for a fact it’d have issues, I just needed something for testing at least. What I ended up doing was running the event on owning client to get the camera trace, then passing that to a separate server event which got the muzzle location in the world, then the server multicasted the spawning and firing of the bullet to that first line trace. This works on the listen server and the client even though I know it’s flawed (unnecessary casts, game feel, etc) but it was all I could figure out on my own.

That was one of the big issues I’ve had, I’ve found tons of tutorials for DEDICATED servers but everything regarding listen servers either didn’t explain things fully/help me wrap my head around using the nodes.

Thank you for the response!

You cannot ever trust clients. Any data they pass up can be malicious.

Client does its own trace for fx etc, then calls the server.
Server does its own trace, then multicasts to have sims shoot.
Server can pass vectors to sims for their shot, but it isn’t technically needed.