Discuss Scratch

Lampert_157
Scratcher
14 posts

TD Grid snapping help

I need help with my tower defense game, I need grid snapping help, I will be thankful for your help
dem_bot
Scratcher
100+ posts

TD Grid snapping help

maybe
(((grid size) * (round (((x or y pos) - (offset)) / (grid size)))) + (offset))

Last edited by dem_bot (Dec. 19, 2025 13:25:01)

Lampert_157
Scratcher
14 posts

TD Grid snapping help

Thanks, but what about the X and Y ?
Arvionyx
New Scratcher
37 posts

TD Grid snapping help

You could just use roundings, here is an example on how you could do it (based on grid size, example grid size will be 10)

(round (((Y pos) / ([^10] of (length of [Y pos])::operators))))

If round is equal to 1 you choose the higher grid if 0 choose lower grid. This is not tested so a few adjustments might be needed for it to work if someone clicked on a place with 4 squares overlapping. The same thing can be used for X pos but just that if 1 go to left and 0 go to right. (Direction to snap to can be changed.) This only works due to the grid size being in the power of 10s (e.g 1, 10, 100 etc.)

If I understood the question wrongly then sorry, it was a bit confusing on what you wanted.

Last edited by Arvionyx (Yesterday 08:28:57)

Lampert_157
Scratcher
14 posts

TD Grid snapping help

I definitely did not understand on what you were trying to tell me, but thanks for trying to help

Powered by DjangoBB