# GM:S 1.4 Need Help with Isometric Cursor Snapping to Grid

Discussion in 'Programming' started by Stoneskull, Dec 4, 2018.

1. ### StoneskullMember

Joined:
Dec 4, 2018
Posts:
2
Hello! I am trying to make an isometric game in GM 1.4.1804 and I need an object to follow the cursor but have it snap to my isometric grid. So far I have my room's grid snap set to 64px by 32px so I can place objects relatively easily but don't have any code built into the objects themselves. My diamond shaped tiles are 64px wide and 32px tall, so I started off by using move_snap(64,32) but that obviously will cause the object to snap between the tiles on their vertices.

I have also tried implementing an offset by figuring out what column the tile is in and adjust the height by 32px downward but this just causes more issues. I've been scratching my head for hours now and I'd really appreciate any help I can get! Thank you all in advance!

2. ### TheouAegisMember

Joined:
Jul 3, 2016
Posts:
6,512
Last edited: Dec 4, 2018

Joined:
Apr 21, 2016
Posts:
2,250
4. ### StoneskullMember

Joined:
Dec 4, 2018
Posts:
2
Thank you for all of that! It'll be really useful for me Although sadly after reading that and trying to apply the formulas I still can't get any farther than before :/ I can get the tile to snap to a grid just find but it will still snap between the isometric tiles and I can't think of how to get it to only snap on the correct places..

5. ### YellowAfterlifeᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀForum StaffModerator

Joined:
Apr 21, 2016
Posts:
2,250
Convert room coordinates to isometric coordinates, snap those to the nearest cell, convert them back to room coordinates.

6. ### Curt LemonMember

Joined:
Jan 3, 2019
Posts:
1
var a, b, c;

a = round(mouse_x / 16) * 16;
b = round(mouse_y / 16) * 16;
c = frac(a / 32);

b += (c * 2) * 8;

draw_sprite_ext(spr_tent_01, 0, a, b, 1, 1, 0, c_white, 0.5);

Here's a script I came up with which seems to snap to grid isometrically for my project. My grid would actually be 32 x 16 pixels.