Discord
Login
Community
DARK THEME

Is grid movement possible in microscript/studio

I've been trying to make grid movement code without much success. I also tryed searching but didnt find code about grid movement for microscript/studio. Any help would be appreciated.

update = function()
  gridx = floor(touch.x / grid) * grid
  gridy = floor(touch.y / grid) * grid
end

draw = function()
  screen.clear()
  screen.fillRect(gridx, gridy, 50, 50, "white")
end

As an example, let's say grid is 50 and touch.x is 155. 155/50 = 3.1. The floor function returns the value rounded down to the lower integer. So floor(155/50)=floor(3.1)=3. 3 * 50 = 150 so gridx will be 150.

Thank you for the explanation I was trying to figure this out for about 2hours

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community