• News

• Industries

• Learning & Support

• Community

• Marketplace

# What could cause a trace to be different from projectile movement?

I am spawning a projectile using a socket in front of my gun, I get the socket transform and apply that to the spawned actor. I am also doing a trace in my HUD class from the socket and drawing a crosshair at where the trace hits; I get the sockets location, add a vector of (0,10000,0) and then rotate it using the sockets rotation. In game the projectile and the trace appear to be about 5 degrees apart in yaw.

Does the projectile have gravity enabled?

It gets weirder, the difference disappears when I turn in one direction and it gets bigger in the other. I moved the trace from my HUD BP to my weapon BP to rule out any timing problems and the behavior is still the same, both the trace and the spawned projectile are using the same rotation. So now I’m thinking if my method of adding y=10000 to the location of the socket for the trace is not the right way to do it? It’s clear that the projectile is going in the direction the gun is pointing and the trace is the one that is off.

Anyone have any ideas?

I’m not entirely sure what you’re trying to do. But I’m going to assume you want to get the point where your projectile is going to hit and then use that location to display some kind of thing.

I made a trace that predicts projectile movement based on initial velocity and launch rotation, which seems to work okay over shorter distances, but I’ve not checked anything over long ones, possibly just needs some fine tuning of a single variable (the number I divide the projectile velocity with) to make it more accurate. Maybe you can use some bits from this for your own thing.

What I am trying to do is much simpler, I want to trace a straight line along my gun’s barrel and draw something where it hits. My gun is a separate actor that is attached to my third person character.

I think the problem I am having is obtaining the direction the gun is pointing in world space.

After much hair pulling and nausea, I’ve figured out what I was doing wrong.

To trace from a socket properly you have to convert it’s location from world to local space, apply the distance that you want to trace in which ever axis the socket is pointing and then transform back from local to world space.

Specifically it looks like this.