tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 11 Jul 2014 09:19 PM |
| I can use math.floor() on X and Z, but I need a part to snap to a weird number like 0.4 or 1.2 on the Y axis. How would I do this? |
|
|
| Report Abuse |
|
|
sbk28
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 2528 |
|
|
| 11 Jul 2014 09:20 PM |
local number = Amount % 0.4 -- (or 1.2) local number = (Amount - number) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 11 Jul 2014 09:24 PM |
| What does amount stand for? |
|
|
| Report Abuse |
|
|
sbk28
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 2528 |
|
|
| 11 Jul 2014 09:26 PM |
Amount would be your X or Z
% is modulus so it returns a remainder after division
for example
3 % 2 = 1
4 % 2 = 0
therefore if your x position was 0.9 and you wanted to move it to the nearest 0.4 ( so 0.8)
0.9 % 0.4 = 0.1
0.9 - 0.1 = 0.8 |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 11 Jul 2014 09:34 PM |
I tried this but it teleported the brick really far away...
mouse.Hit.Y % Increment
Increment is either 1, 0.4, 0.2, or 1.2 |
|
|
| Report Abuse |
|
|
sbk28
|
  |
| Joined: 15 Nov 2008 |
| Total Posts: 2528 |
|
|
| 11 Jul 2014 09:35 PM |
| http://wiki.roblox.com/index.php?title=Arithmetic_operator |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 11 Jul 2014 09:39 PM |
Ehh... I tried using what it said and tried these... none of them work:
ClonedBrick.Position.Y-(mouse.Hit.Y % Increment)
ClonedBrick.Position.Y+(mouse.Hit.Y % Increment)
(mouse.Hit.Y % Increment)
|
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 11 Jul 2014 10:34 PM |
function SnapToGrid(part, grid) local pos = part.Position return Vector3.new(pos.X-pos.X%grid.X, pos.Y-pos.Y%grid.Y, pos.Z-pos.Z%grid.Z) end
local part = Workspace.Part SnapToGrid(part, Vector3.new(1, 0.4, 1))
That seems to work. 'part' is the part to snap, 'grid' is what number to snap to on each axis, a Vector3 value. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 12 Jul 2014 04:27 PM |
| Ooh, sparkly. Lemme try it. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 12 Jul 2014 04:46 PM |
Eh, I tried this, but it didn't work:
function SnapToGrid(part, grid) local pos = ClonedBrick.Position return Vector3.new(pos.X-pos.X%grid.X, pos.Y-pos.Y%grid.Y, pos.Z-pos.Z%grid.Z) end
SnapToGrid(ClonedBrick, Vector3.new(1, 0.4, 1))
ClonedBrick is the part I want to snap to a grid. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 12 Jul 2014 04:57 PM |
Oops, I think I combined two different scripts in my head.
function SnapToGrid(part, grid) local pos = part.Position part.Position = (pos.X-pos.X%grid.X, pos.Y-pos.Y%grid.Y, pos.Z-pos.Z%grid.Z) end |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 12 Jul 2014 05:11 PM |
| Where do I tell the grid what to snap by? Would I replace pos with Vector3.new(1,0.4,1)? |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 12 Jul 2014 05:17 PM |
No... That's a function that I made so it would be easy for you.
SnapToGrid( part, grid )
When you call the function, just change that second argument to Vector3.new(1, 0.4, 1)
So like
SnapToGrid(Workspace.Part, Vector3.new(1, 0.4, 1)) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 12 Jul 2014 05:27 PM |
It works! Thanks.
I really need to learn how to use functions better... I learned everything out of order, so I know advanced topics fluently while I lack at some of the simpler ones. |
|
|
| Report Abuse |
|
|