I have made a simple shooting game using multiple YouTube tutorials. Still, recently I realized a bug in the game that I couldn’t find the solution for, even after researching and watching other tutorials on the same topic.
The Bug:
When I move left and right quickly while shooting, sometimes (randomly) the line trace will shoot towards the wrong direction(mostly left and right), to understand the problem better, I included a video here:
After some debugging, I realized that nothing other than the camera’s forward direction could have caused it, I will leave a screenshot of my shooting mechanic blueprint here:
I’m not sure of the situation, but based on your screenshot it looks like you’re using a ThirdPerson camera as the origin of your shot, just based off the name “FollowCamera”, which is the default name for the ThirdPersonCamera in BP_ThirdPersonCharacter. That might be the problem.
If you have a First Person Camera, try using that instead.
If you don’t have a First Person Camera and you’re doing some Zoom / POV or camera manipulation to fake the FPV, add a First Person Camera without a SpringArm and use this camera instead. That should stabilize the Shot Origin.
I removed the camera completely and created a new one, set its position and made sure it used pawn as rotation… But unfortunately, nothing was changed and the problem was still there.
The only things that are affecting the camera rotation are the camera shakes and recoils, but I had the same problem before even adding them so they couldn’t be the problem.
You have a SpringArm there attached to your camera and holding the FirstPerson mesh, and the Camera is attached to another mesh.
Maybe some of the settings of these components are messing with the perspective.
Try deleting the Spring arm, and moving the camera out of the Mesh.
And set the camera with
If that still doesn’t work, you can try adding a ThirdPersonCamera, making the FPCamera visible and see what’s going on there.
Camera Shake shouldn’t affect the direction unless you’re directly rotating the camera manually or through animation, which could happen if the the Mesh it’s attached to has animations.
You should do something like this if not exactly this, make sure your camera or component of choice is in the correct place, you could even do it from the gun comp if you wanted to but this won’t give the feels like of a game rather the frustration of using a “real” gun without being able to aim it properly
If your changing cameras to do your aim down sights that looks like what’s the cause
you can do a FOV change to get a similar effect
You’d always want to get the same camera/object to trace from or the result changes
So what’s happening here is a little hard to see, but at least it looks like you’ve done it right actually and it’s just the line looks wrong, but the hit point appears to be dead where you’d want it every time
it may be easier to see this if you switch debug draw to one frame or hide the line itself and only show the hit point
failing all of this something changes it unexpectedly outside of your macro and that’s not shown very well in the video because it looks right
I actually tried removing the sprint arm completely before and it didn’t work, but I did it again, I also made sure the camera is only parented the capture collider and nothing else this time (Not parented to mesh)
But after doing all that the results were the same
I can’t see all of it to be sure, you may call it a function in your head but what i was referring to is what happens with the Outputs Node after your line trace ( firing the gun probably )
if you didn’t add the bit about getting the cameras rotation this could by why as well, can we see the now updated BP
Also the components should be arranged
Capsule
Spring arm
Camera
Character
The capsule will rotate its children
spring arm
character
The Spring arm just maintains the distance of the attached child
My weapon and my characters have separated and each one of them also has dependencies so sharing just a uAssset wouldn’t be possible.
To my knowledge, since we are debugging the line trace, what happens after the line trace doesn’t matter, I can try removing them but I don’t think it would affect it at all.
Also the arrangement of my character hierarchy,( mostly the sprint ) is spiffily made so the arm+gun would have a lag, that’s why the spring arm is inside of the camera and not outside.
I was thinking of recreating the project or just the character, that might help the problem go away, but I also really want to learn the reason for this problem.
Does the sudden angle change happen if you don’t move and just shoot standing still?
Also, it’s weird that the angle seems to be exactly the same for the wrong trace to the right and the one to the left. It’s almost like the Forward Vector of the camera get’s rotated.
Could you try changing the “Fire” input to a Key instead of the mouse and print the ForwardVector of the Camera on each shot? I say this so that you can test without moving the mouse and rotating the player.
I’ve watched the video a few times at x0.12 speed and the camera doesn’t twist at all.
Just out of curiosity, you could try using the Actor Forward Vector instead, just to see what happens.
Can you clarify that you’ve fixed the line trace similar to what i showed above earlier… using the rotation and the camera component itself.
Instead of getting the camera from the player movement, just to also narrow down the possibilities
getting the camera from the player movement this is my current theory… i don’t think it would matter and it would seem your only using one camera…
My one works flawlessly
so it has to be the way its executed assuming you’ve done it as close to the picture as possible
Notably I’m using visibility channel and your using camera channel but that should not be the issue just worth mentioning as a diff
Turn them off at least temporarily un connect it or use a branch just to narrow down the area the problem could be even further
My guess is its the player arms and camera are offset from the camera somehow because of the
spring arm
I’ll be surprised honestly if this isn’t the problem
It’s definitely a problem of where the camera gets moved to, the line trace itself is fine so without a doubt its something about how the camera is setup or moved/effected
The sudden angle changes only when I move left and right quickly and sometimes when I move backwards.
also if it were the camera rotating causing the sudden change, for example, rotating suddenly or twisting, I would have noticed it as the player is looking from the same camera.
I will try out what you said and let you know if it works.
Glad you found it, sometimes our suggestions are useless but talking about it helps you realize how its all related and what to check or what you may have breezed over and said “its fine” i had a guy practically have to beat me with a stick to realize how pure nodes were affecting a problem i was having