Left-Clicking causes Tank to look in a Different Direciton

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.

Any help would be appreciated!

Would you mind sending me your project using the following link?

https://gdev.tv/projectupload

Please use File > Zip Project within Unreal as this will ensure only required files are zipped up and things like the Binaries are excluded.

1 Like

Just uploaded my project! I submitted two forms, disregard the first because I neglected to zip from Unreal, but the second submission I did.

Thanks for the help!

Also not sure the relevancy, but I am developing on macOS in case that gives you any additional information you might need.

It seems to be working fine for me. What mouse are you using?

Logitech MX Anywhere Mouse

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.

That is very interesting to hear you get the opposite effect :sweat_smile:

I guess for the time being I’ll keep it as is since it solves my issue, but if I find any new solutions to this problem I’ll post about it again.

Thanks for the help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms