Just only allow movement along set intervals (like below). Alternatively you could "snap to a grid" (there's a wiki article on that), but I'm pretty sure that's not the effect you're looking for.
when gf clicked forever if<key [right arrow v] pressed?> repeat (10) change x by (1) end end if<key [left arrow v] pressed?> repeat (10) change x by (-1) end end if<key [up arrow v] pressed?> repeat (10) change y by (1) end end if<key [down arrow v] pressed?> repeat (10) change y by (-1) end end
Offline
Assuming it is top-down, the below script is one way. If it is more 3-D looking, I'd have a 2-D list with whether a block can be moved through and check that (if that's the case, I can try to give you a script for that).
when gf clicked forever if<key [right arrow v] pressed?> change x by (10) if<not<touching [wall v]?>> change x by (-10) repeat (10) change x by (1) end else change x by (-10) end end etc.
Offline
What do you mean "accurate". A smaller grid?
Offline
I'm not sure exactly what you want. Do you want a script that returns a sprite's x and y position on the grid? A script that uses a 2D array for wall collision?
Offline
A script that uses a 2D array for wall collision?
The script for a sprite's x and y position on a grid looks something like this:
set [x v] to ((round(((x position)-[horizontal shift])/(tile_size)))+[some number]) set [y v] to ((round(((y position)-[vertical shift])/(tile_size)))+[some other number])horizontal and vertical shifts, as well as "some number" are simply correction values that depend on a ton of things (like where the center of the sprite is, how the grid is shifted, etc.). The simplest way to find them is trial and error. It's difficult to explain how to find them though, anyone want to give it a shot?
Offline
((x-hs)/(tile_size)) + some number
Thinking back on it, "horizontal shift" and "some number" are probably the same number. I'm away from home visiting relatives right now so I can't confirm it
Offline