Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do people make 'tile' based tycoons/building in roblox?

Asked by
alibix123 175
7 years ago

I'm not sure how to explain it but when in these games you have a sort of building tool you can only place it in a specific way, like the ROBLOX stamper tool. Are there literally invisible tiles or is there some fancy math going on?

0
They use modulo and math.floor ect to round to the nearest sqware giveing a grid like effect User#5423 17 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

It's not magic

I just had to debunk that for you. You're welcome. What actually happens is that when they get your mouse hit position (mouse.Hit.p) they round off the X and Z axes. Here's an example implementation:

local function RoundTile(MousePosition, TileSize)
  -- I've been using js too much recently I just tried to use {} for the function body.
  local x,z = MousePostion.x, MousePosition.z
  x = math.floor(x/TileSize + 0.5)*TileSize
  z = math.floor(z/TileSize + 0.5)*TileSize
  return Vector3.new(x, MousePosition.y, z);
end;
  • MousePosition is the position that the Mouse is pointing at (Mouse.Hit.p)
  • TileSize is the size of every tile. Simples. squeak
Ad

Answer this question