|
| 13 Jun 2015 12:35 PM |
Ok so Im doing this again because I didn't explain my other one very well. A lot of people got confused and stuff, so Im going to explain what I mean here.
My map, like the quarry and epic mining 2, is made up of loads of small blocks, each have a size of 5 (that's 5,5,5).
In my game, you can build structures on the landscape, and you can drag the model where you want it to be before you place it.
But there is a certain rule i want to implement: You cannot place the model ontop of a gap where blocks meet. The landscape is effectively a grid.
So to do this I want to adapt my script so that the models are basically fixed when moving - just like in studio, where you can snap to 1 studs - the part has to move one stud instead of it being able to move inbetween the studs.
So basically, I want to make it so that when users drag the models, the models snap onto the grid - making the models move 5 studs. Its basically like dragging parts in studio where the scale is set to 5 studs.
This is the script I have so far (yes, localscript):
script.Parent.MouseButton1Click:connect(function() game.Workspace.BrickHouse:Clone() for i, v in pairs (game.Workspace.BrickHouse:GetChildren()) do if v:IsA('Part') then local player = game.Players.LocalPlayer local Mouse = player:GetMouse() Mouse.Move:connect(function() game.Workspace.BrickHouse:MoveTo(Mouse.Hit.p) end) end end end)
|
|
|
| Report Abuse |
|
|
tyzone
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 1726 |
|
|
| 13 Jun 2015 12:38 PM |
game.Workspace.BrickHouse:MoveTo(Vector3.new(math.floor(mouse.Hit.p.X/5)*5,math.floor(mouse.Hit.p.Y/5)*5,math.floor(mouse.Hit.p.Z/5)*5))
This should create a 5-stud grid. The grid might not be in sync with the one you have already created. Feel free to add an offset to any incorrect coordinate. For instance, if the model always goes 1 stud to the right, you could add:
[...]math.floor(mouse.Hit.p.X/5)*5 - 1, [...]
eww no pink shaggy |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 01:58 PM |
Ok so I tried it, and I find that whenever I move it in any axis, it always goes in a pattern of 6,4,6,4...
What should I do? |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:12 PM |
local Object = Your Model
Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X/4), Hit.Y - math.fmod(Hit.Y/4), Hit.Z - math.fmod(Hit.Z/4)
Object:MoveTo(Vector3.new(N)) end)
- “My dear, here we must run as fast as we can, just to stay in place. And if you wish to go anywhere you must run twice as fast as that.” |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Jun 2015 02:12 PM |
Sorry, where it says :MoveTo(Vector3.new(N)) Should actuall be:
:MoveTo(Vector3.new(X0,Y0,Z0))
- “My dear, here we must run as fast as we can, just to stay in place. And if you wish to go anywhere you must run twice as fast as that.” |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:14 PM |
@Dev
Where did you pull out N from?
It says its an unknown global. |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Jun 2015 02:16 PM |
Wait...hang on
Players.Player1.PlayerGui.ScreenGui.TextButton.LocalScript:11: bad argument #2 to 'fmod' (number expected, got no value) |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:18 PM |
Hm. Okay try changing:
local Hit = Mouse.Hit
to
local Hit = Mouse.Hit.p
- “My dear, here we must run as fast as we can, just to stay in place. And if you wish to go anywhere you must run twice as fast as that.” |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:21 PM |
Oh jeez, I see where I went wrong.
Rather than math.fmod(Hit.X/4) it should be math.fmod(Hit.X,4)
Here's the updated code:
Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X,4), Hit.Y - math.fmod(Hit.Y,4), Hit.Z - math.fmod(Hit.Z,4)
Object:MoveTo(Vector3.new(X0,Y0,Z0)) end)
- “My dear, here we must run as fast as we can, just to stay in place. And if you wish to go anywhere you must run twice as fast as that.” |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:26 PM |
Ok great.
One slight problem though
It always goes 6,4,6,4,6,4 in a patten whenever and wherever I move it.
I have no idea why but it's wierd. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:27 PM |
| It might not be to do with your script though, considering it did the same thing with the last one. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:32 PM |
| Huh, I'm not sure what you mean by 6-4-6-4? Can you describe that a little clearer or maybe a screencap? |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:37 PM |
OK so I had a go now, and It always goes by four. In other words its snapped to 4 studs per move, not 5.
It's snapped to 4 studs, that's what I meant.
Sorry for the confusion.
|
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 02:39 PM |
OH. Okay that's a fault on my side, change the
'4's in the math.fmods to '5's
so math.fmod(Hit.X,4) should be math.fmod(Hit.X,5) and so on for Y and Z |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Jun 2015 02:53 PM |
WAAAAIT...
sorry for confusing you like this, but this is pretty wierd.
Wherever I move it, it goes in this pattern: It moves 4 studs, then it moves 6 studs.
I have no idea why its doing this - could it be the position of the textbutton? |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 03:02 PM |
Huh. That's weird. Nothing else should be affecting the position codes.
I have an idea, I'm not sure if it will work but it's worth a try.
Can you make a 5x5x5 bounding box inside your model.
(Like this: http://puu.sh/inC0U/d83db3e03a.jpg
The chair being my model, and the white box being the "bounding box"
Make BoundingBox a child of the model, and set the Model's PrimaryPart property to the box.
Model.PrimaryPart = BoundingBoxPart Move:MoveTo() -- As long as the Model's PrimaryPart is set before you call :MoveTo, this should work. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 03:27 PM |
This is the script I have (This still does the strange glitch)
script.Parent.MouseButton1Click:connect(function() game.Workspace.BrickHouse:Clone() local Object = game.Workspace.BrickHouse for i, v in pairs (game.Workspace.BrickHouse:GetChildren()) do if v:IsA('Part') then local player = game.Players.LocalPlayer local Mouse = player:GetMouse() Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X,5), Hit.Y - math.fmod(Hit.Y,5), Hit.Z - math.fmod(Hit.Z,5) Object.PrimaryPart = Object.BoundingBox Object:MoveTo(Vector3.new(X0,Y0,Z0)) end)
end end end)
The line "Move:MoveTo()" doesnt seem to be accepted, so i replaced it with the original line - Object:MoveTo(vector3...)
Im hoping ive done something wrong, because I got to fix this... |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Jun 2015 03:44 PM |
Okay, I see what you're doing.
You've sort of ordered it wrong.
Rather than A,B,C you've gone and done A,C,B
---------
local Player = game.Players.LocalPlayer local Mouse = player:GetMouse()
-- Player and Mouse should be defined outside of all the lines of code, pretty much at the very top of the script.
script.Parent.MouseButton1Click:connect(function()
local Object = game.Workspace.BrickHouse:clone() Object.Parent = game.Workspace() for i = 1, 10 do Object:MakeJoints() end Object.PrimaryPart = Object.BoundingBox
Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X,5), Hit.Y - math.fmod(Hit.Y,5), Hit.Z - math.fmod(Hit.Z,5) Object:MoveTo(Vector3.new(X0,Y0,Z0)) end)
end
|
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 13 Jun 2015 04:02 PM |
This seems to be working:
player=game.Players.LocalPlayer Mouse=player:GetMouse() Object=workspace.newPart pt=Object:findFirstChild('newPart')
Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X,5), Hit.Y - math.fmod(Hit.Y,5), Hit.Z - math.fmod(Hit.Z,5) Object:MoveTo(Vector3.new(X0,Y0,Z0)) print(X0..Y0..Z0) pt.Position=Vector3.new(X0,Y0,Z0) end)
The MoveTo is alowing offset from what that fmod returns (which is exactly correct), but setting the part's Position directly seems to fix it. |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 13 Jun 2015 04:08 PM |
| Just make sure that each part already anchored in the worspace, including the plate, has all the axes of its size and positions evenly divisible by 5. |
|
|
| Report Abuse |
|
|
|
| 13 Jun 2015 04:13 PM |
Thanks but it's still doing the problem - goes 4 studs then 6
I think this might be some glitch or something I just dont get why this isnt working.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse()
script.Parent.MouseButton1Click:connect(function()
local Object = game.Workspace.BrickHouse:clone() Object.Parent = game.Workspace for i = 1, 10 do Object:MakeJoints() end Object.PrimaryPart = Object.BoundingBox
Mouse.Move:connect(function() local Hit = Mouse.Hit local X0, Y0, Z0 = Hit.X - math.fmod(Hit.X,5), Hit.Y - math.fmod(Hit.Y,5), Hit.Z - math.fmod(Hit.Z,5) Object:MoveTo(Vector3.new(X0,Y0,Z0)) end)
end)
|
|
|
| Report Abuse |
|
|