Innacurate line trace for camera on spring arm

I have a simple setup (similar to the default 3rd person controller) where the camera is attached to the camera spring arm which is attached to the character.

When I shoot a raycast from camera’s transform: GetWorldLocation and GetForwardVector, I get inaccurate hit results when the character is rotating rapidly. (spamming the keys ‘A’ and ‘D’). And by inaccurate, my hit scan particle effect gets spawned on the left and right of the center of the screen (get worse as the target is farther away).

I’m guessing that the error is caused from the camera boom updating after the action event i receive in the character. All of the inaccurate line trace intersects (like an ‘X’) at the pivot point where the camera boom rotates.

Any ideas on how I can fix it?

Blueprint setup:
The line trace is in a function called “fire gun”

And the fire is called from a notify event from the animation montage


I want the player to orient to the direction of the movement so the orient rotation to movement checkbox is on


The issue doesn’t occur when it is off, but i need the character to orient to the movement so this isn’t an option

Can you show the line trace setup?

Thanks for the reply, I added the screenshot to the post

Do you have a Spring Arm lag enabled?

What happens if you just run right and shoot? Is the offset always the same or does it catch up in a second or two?

I have everything in lag disabled, and the offset only happens once everytime the direction is changed (but not for jumping)

Just tested it. Everything connected to the spring arm gains about 5 degrees rotation for about 0.3 second when you start moving right or left, even though visually the rotation doesn’t change. None of the Spring Arm options seem to fix it.

If you haven’t found anything on this issue on the Internet, maybe consider submitting a bug report? It’s not supposed to do that.

Thank you for the help, I just submitted a bug report.

Hey so, maybe the bug report is premature.
You have recoil on the gun. Are you 10000% sure that the animations being played aren’t altering the character’s rotation and causing the effect?

Most importantly. Set slomo to .1 and check to see if the camera actually ever moves.

Last thing. You have a cross hair. You could maybe get the world location of whatever is under the cross hair as the end position of a line trace?
If you are checking for hitting a target the line trace should probably operate from muzzle front to area under cursor.
Be it the forward vector of the camera or not (the reticle often gets offset in most games).

If you are using an aim offset, maybe the front of the gun’s forward vector could provide a better start and end point altogether. It is obviously affected by animation though, so thats why getting the area under the cursor as the end of the trace may be preferable.

IDK, 5 degrees for .3 seconds is more than enough to see even without slo-mo. I even made the cube way longer so that even 1 degree would mean a lot of linear displacement of the corners. Again, not a single twitch.

And even without talking about right or wrong ways to do stuff, if an object doesn’t rotate but the engine thinks that it does, that’s not right and should be fixed.

No recoil, no crosshair, nothing. You can test it in a default third-person template yourself.

I added a cube to the spring arm so I could see it at runtime, and I set Print String on tick to show the cube’s World Y rotation.When you change the movement direction, visually the cube doesn’t rotate at all, but the print string values change by about +5 and -5 degrees depending on the direction.

Use slomo. If you are getting ±5 results it doesn’t mean that the change isn’t occurring visually as well. It might just mean its too fast for you to see.
However I don’t think tracing from the camera forward vector is a good idea anyway, so there’s that…

If this is usually isn’t a problem, how is this usually implemented? I am fine with changing my implementation to the standard way. I come from a unity background so may not be familiar with unreal stuff yet

Mostly depends on your project.
You could try to trace from the muzzle to the spring arm’s end point×forward vector×distance. See if that provides a more reliable result.
Overall usually, as I said, you use the area under the cursor which you get from the widget.
Technically your cursor could be Anywhere - many games offset it up for instance.
The function to look at is convert screen location to world space.

Okay, I changed it for it to be driven by viewport instead and its much better. Although it still seems to be behind by a frame or so, its acceptable since the viewport doesn’t inherit rotation from the character controller. Does unreal have something similar to unity’s [Script Execution Settings][1]? It feels like the problem is comming from the camera boom is updating after the actors blueprint

After experimenting with unreal some more, I think I found couple of solutions so I thought I might share it.
The root cause of the issue was the fact that the tick was running too early (before the camera location gets updated in the spring arm)

  1. Use DeprojectScreenToWorld - This option will not have the issue of any weird rotation from the spring arm since the viewport always has the correct rotation. However I assume it’s using the viewport from last frame since the location and rotation is always a frame behind of what the shows up on the screen.
  2. Change the tick group to post update work. This will force the tick to run at a point much after a lot of things have finished updating. This might not be an option for some since unreal only provides one tick (group) per actor. (I assume no LateUpdate equivalent in unreal)
1 Like