I made a short video of this.

Basically, when the screen scrolls with the camera, the character begins firing at the incorrect mouse position. You can see where I am clicking the whole time. As we move towards the right edge (the more we scroll), you'll notice the distance away from the correct position increases. The shooting mechanic worked just fine before I added the camera.

I'm using a translation matrix to implement my camera.

What could be causing this?

  • \$\begingroup\$ This looks like the same problem as Mouse location is off due to camera. Is Jesse's answer there helpful? \$\endgroup\$ – Anko Feb 14 '14 at 11:06
  • \$\begingroup\$ It works perfectly! To calculate the distance in X the mouse was away from the player, I was using distance.X = mouse.X - player.Position.X. I needed to convert mouse.X (screen position) to world coordinates, so added the position of the camera to that and voila! distance.X = camera.GetWorldPosition(mouse.X) - player.Position.X You have been tremendously helpful. Thank you so much. \$\endgroup\$ – atkayla Feb 14 '14 at 12:44
  • \$\begingroup\$ Happy I could help. :) \$\endgroup\$ – Anko Feb 14 '14 at 13:27

All objects within the game can interact with one another in a persistent manner regardless of camera location. However, items that aren't within the game cannot. Whatever translation the objects have undergone, the opposite needs to be done before the mouse can interact with them. For example

Say you more all objects using xOffset by 500px, you then subtract xOffset from all objects so that they appear to be in the correct place. if you wanted the mouse to interact with them, you'd have to add the xOffset back onto the Mouses x coordinate.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.