Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Getting the position of the mouse in a room

A topic by ratratratrats created Feb 22, 2023 Views: 237 Replies: 3
Viewing posts 1 to 2

Hi! Pictured here is a small test environment I've made. I was curious how I would go about snagging the position of the mouse in the room.  I've annotated some debug text on screen here, on the left you can see the players position, and on the right my mouse (which didnt make it into the screenshot but it's a little to the left of the player)

The mouse position seems to go into wild numbers whenever the camera is rotated. On the default axis it seems to work somewhat as I would expect - like when the room is first loaded up and the camera is facing straight north the mouse_x is the expected value (mouse_y is not).

Any thoughts? The projection of the camera seems to have a huge impact on the values.

So essentially you need to do some matrix multiplication of the screen coordinates to convert them to world coordinates and visa versa. The camera in fauxton uses an actual 3d camera so you can follow along this tutorial to get the right coordinates:

I cannot recommend dragonitespams gamemaker 3d tutorials enough! If you are ever interested in learning full 3d in GM, he has a huge catalog of various tutorials for creating 3d environments and such in Game Maker! 
Deleted 1 year ago
(+2)

Great reference! I managed to get it working after a bit of tinkering. I ended up making my own simple raycasting funcion which assumes we are looking for an intersection on the z = 0 plane.  Anyone reading this is welcome to steal it:

function simple_raycasting( dx, dy, dz, ox, oy, oz ) {
    var _t = oz/-dz;
    return [ox + dx*_t, oy + dy*_t];
}

Hello, I'm new to game development and I'd like to know how to implement your function. I didn't understand which values to pass 馃ゲ. (dx, dy, dz)