gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 24 May 2016 11:28 PM |
| So I'm sure you all have used a building tool before, where you choose a block to build with and where ever you click it makes the choice you made appear there right? And usually, it has a grid it goes on, so you can't place it and have it collide with other objects, right? How do I make a grid through a script? Please don't just post a script for me, I want to learn how to make it, so post some things that I would probably need, like do I need to use tables, functions, variables, and stuff like that. Thanks to everyone that replies! |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 24 May 2016 11:29 PM |
use math.floor and division/multiplication of cordinate values to create a grid coordinate system
the more you divide the number , floor it, then multiply it by the origional dividing number will return different grids
or use moveto and it will auto grid i believe |
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 24 May 2016 11:31 PM |
oh man, maybe grids are 2 complicated 4 me cause I don't know any of that stuff yet...
To the wiki it is! |
|
|
| Report Abuse |
|
|
|
| 24 May 2016 11:36 PM |
math.floor(component/grid + 0.5)*grid
Think of it like "rounding to the gridth's place" because that's exactly what it is. |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 24 May 2016 11:36 PM |
to snap to a certain location
local grid = 4 local pos = Vector3.new(35.234,23.2342,89.9234) --idk local snapped = grid*Vector3.new(math.floor(pos.X/grid),math.floor(pos.Y/grid),math.floor(pos.Z/grid))
|
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 24 May 2016 11:38 PM |
ok psuedo code its not really that complicated
position = Vector3.new(55.5,66.4,77.2)
local x = math.floor(position.x/10) local z = math.floor(position.z/10) newpos = Vector3.new(x*10, position.y, z*10)
print(newpos) -- (50, 66.4, 70)
for example and would be a 10x10 grid, where anyposition within that 10x10 grid would return that same position! |
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 24 May 2016 11:38 PM |
New question, I have this:
(math.floor(m.Hit.p), m.Hit.p+part.CFrame.lookVector) * CFrame.new(0,1.5,0)
but it won't floor m.Hit.p because it is not a number, what is the code to get the number of m.Hit.p?
I feel like its probably something like m.Hit.p:GetNumber() |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 24 May 2016 11:39 PM |
u gotta separate p from the vector3 to individual numbers
|
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
| |
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 24 May 2016 11:41 PM |
p.x would give the x of p
p would be like (35, 25, 54)
(x, y, z) p.x would return x aka 35 |
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 24 May 2016 11:44 PM |
so do it like this? math.floor(m.x,m.Hit.x,p.x) |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 24 May 2016 11:45 PM |
You need to do each component separately.
math.floor(m.Hit.p.x) math.floor(m.Hit.p.y) math.floor(m.Hit.p.z)
|
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 24 May 2016 11:46 PM |
And then at the end re-combine all the components into a new Vector3 or CFrame.
|
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 24 May 2016 11:47 PM |
| Oh so I could make a table with them, then combine them and make them a variable to put into math.floor(variable)? |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 24 May 2016 11:48 PM |
You have to do the math on x, y, and z separately.
|
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 24 May 2016 11:48 PM |
not really a point to make a table it'll make a 'invisible' grid system |
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 25 May 2016 12:04 AM |
| I want an invisible grid though |
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 25 May 2016 12:14 AM |
Would this work?
local table1 = { x = math.floor(m.Hit.p.x); y = math.floor(m.Hit.p.y); z = math.floor(m.Hit.p.z); } for i,v in pairs(table1) do print(v) part.CFrame = CFrame.new(v, m.Hit.p+part.CFrame.lookVector) * CFrame.new(0,1.5,0) part.Anchored = true end end end end) |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 25 May 2016 12:17 AM |
No, that would not work. Come on dude, I gave you perfectly good code to work with.
local grid = 4 local pos = m.Hit.p local snapped = grid*Vector3.new(math.floor(pos.X/grid),1.5,math.floor(pos.Z/grid)) part.CFrame = CFrame.new(snapped,snapped+part.CFrame.lookVector)
|
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 25 May 2016 12:18 AM |
position = m.Hit.p grid = 4 -- grid size in studs
local x = math.floor(position.x/grid) local z = math.floor(position.z/grid) newpos = Vector3.new(x*grid, position.y, z*grid)
move brick to newpos change grid to the size of ur invisible grid
|
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 25 May 2016 12:18 AM |
| But I told you, I need to learn, not copy from other people! If I copy from you, I won't learn from you. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 25 May 2016 12:19 AM |
why are you using a table tho
i told u not to use a table!
USE A DESK OR A COUNTER OR LITTERALLY ANY FURNITURE |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 25 May 2016 12:21 AM |
I'm not suggesting you use my code verbatim. However, there really are only a few correct ways to do this. Both wowgnomes and I are suggesting similar and valid solutions, so trying to learn by doing something completely different won't help.
|
|
|
| Report Abuse |
|
|
gum444
|
  |
| Joined: 06 May 2011 |
| Total Posts: 549 |
|
|
| 25 May 2016 12:24 AM |
| I see, so I guess i'm forced to use both of your codes (btw, neither work correctly, 2eggnog's spawns the brick a few studs in the air, and the other doesnt work at all.) |
|
|
| Report Abuse |
|
|
2eggnog
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 1351 |
|
|
| 25 May 2016 12:25 AM |
I set it to y = 1.5 because that's what you were using. Change that value.
Seriously, we're not here to spoon-feed you the answers. Use your brain and work with what we've given you.
|
|
|
| Report Abuse |
|
|