I recently implemented the functionality that allows the Tank Pawn to rotate the turret to follow the mouse cursors hit result, however I noticed through my play testing that if I hit left-click at any point, it places the cursor in a different position which in turn rotates my Tank. I thought this would be resolved after implementing the fire functionality but it still occurs and I’m not quite sure why.
Left-Click shouldn’t trigger anything other than Fire since that is all I’ve done in my C++ scripts.
There are no error or warning messages to debug from so not sure how to solve this issue.
I was play testing again and I might have additional information that might help.
When you first run the game, the tank will follow the cursor as intended and you can even left-click to fire once and everything seems to be fine. However, after that first left-click, any subsequent left-clicks that happen afterwards will actually reset the cursor to the original impact point of the first left-click.
I tried looking through BasePawn.cpp and Tank.cpp to uncover the code that may be causing this, but cannot figure it out yet.
I fixed my issue, but just want to make sure it’s a viable solution.
Since I couldn’t find any issues in my code, I was going through the Input Settings via “Project Settings → Engine → Input” and tested modifying the “Viewport Properties” for Mouse Capture.
New Settings (Fixed Issue):
Capture Mouse on Launch = Checked
Default Viewport Mouse Capture Mode = Capture Permanently Including Initial Mouse Down
Default Viewport Mouse Lock Mode = Do Not Lock
Old Settings (Issue Persists):
Capture Mouse on Launch = Checked
Default Viewport Mouse Capture Mode = Capture Permanently Including Initial Mouse Down
Default Viewport Mouse Lock Mode = Lock on Capture
Would you mind confirming whether or not this is fine to do? I’m not sure if this could cause any additional issues down the road so want to cover my bases.
Locking means that the cursor can’t go beyond the viewport bounds. If I set it to Do Not Lock then I can close applications on my other monitor. Lock On Capture means it will be locked to the viewport when you click inside it.
Interestingly I get the opposite behaviour sort of if I click within Unreal when I know the cursor would be out of the viewport but still within the Unreal Editor.