Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Hexagon grid snaping
- TurtleCoder10901
-
Scratcher
11 posts
Hexagon grid snaping
I need a script that takes mouse coordinates and snaps them to a hexagon grid.
Grid snapping on a square grid looks like this:

How do I do this on a hex grid.
Grid snapping on a square grid looks like this:

How do I do this on a hex grid.
- 098765432154321
-
Scratcher
500+ posts
Hexagon grid snaping
I think this should work
Hexagon grid clone script:
Item grid position script:
when green flag clicked
switch costume to [is a square v]
repeat (any number)
create clone of [Hexagon Grid v]
end
Hexagon grid clone script:
when I start as a clone
go to x: ((x position) + (any number)) y: ((y position) + (any number))
if <touching [edge v] ?> then
set x to (any number)
change y by (any number)
end
wait until <<<touching [item 1 v] ?> or <touching [item 2 v] ?>> and <not <mouse down?>>> // you can add more item names
if <<touching [item 1 v] ?> or <touching [item 2 v] ?>> then // you can add more item names
set [get X v] to (x position)
set [get Y v] to (y position)
else
set [get X v] to [not pointing to hexagon]
set [get Y v] to [not pointing to hexagon]
end
broadcast [get item grid pos v]
Item grid position script:
when I receive [get item grid pos v]
if <<(get X) = [not pointing to hexagon]> and <(get Y) = [not pointing to hexagon]>> then
stop [this script v]
end
switch costume to [is a hexagon v]
go to x: (get X) y: (get Y)
Last edited by 098765432154321 (June 5, 2019 17:56:25)
- 098765432154321
-
Scratcher
500+ posts
Hexagon grid snaping
https://scratch.mit.edu/discuss/topic/349525/ may help.I litterally saw this when I edited my post the 3rd time XD
- colinmacc
-
Scratcher
1000+ posts
Hexagon grid snaping
I need a script that takes mouse coordinates and snaps them to a hexagon grid.
Grid snapping on a square grid looks like this:
How do I do this on a hex grid.
Lost in the thread @deck26 posted, I made an example project of hex grid snapping..
https://scratch.mit.edu/projects/305955877/
- Discussion Forums
- » Help with Scripts
-
» Hexagon grid snaping



