generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: moving parts to a masterpart

Previous Thread :: Next Thread 
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
30 Aug 2014 10:40 PM
How do people go about moving a bunch of bricks to one main brick?

I don't mean by teleporting.. I mean like.. floating to the space every tenth of a second or so until they reach the space.

What methods and such do I need for this?
Report Abuse
DonFeskeral is not online. DonFeskeral
Joined: 05 Feb 2014
Total Posts: 6555
30 Aug 2014 10:41 PM
I think you can just use bodythrusts,bodypositions, or an innumerable amount of stuff
Report Abuse
Bobobob12 is not online. Bobobob12
Joined: 23 Jan 2008
Total Posts: 5350
30 Aug 2014 10:46 PM
like, are we talking in or around the main brick?

because if you want everything to go into a epicenter just use a while loop with a for loop inside

local main = game.Workspace.Main --where you want to move to
local model = game.Workspace.Bricks --all the bricks you want moved

local working = true

while working do
for x, y in pairs(model:GetChildren()) do
working = false
if y.Position ~= main.Position then
y.CFrame = CFrame.new((CFrame.new(y.Position, main.Position)*CFrame.new(0,0,.1)).p)
working = true
end
end
wait()
end
Report Abuse
Bobobob12 is not online. Bobobob12
Joined: 23 Jan 2008
Total Posts: 5350
30 Aug 2014 10:47 PM
make it -.1, sorry
Report Abuse
Bobobob12 is not online. Bobobob12
Joined: 23 Jan 2008
Total Posts: 5350
30 Aug 2014 10:50 PM
local main = game.Workspace.Main --where you want to move to
local model = game.Workspace.Bricks --all the bricks you want moved

local working = true

while working do
working = false
for x, y in pairs(model:GetChildren()) do
if (y.Position - main.Position).magnitude > .2 then
y.CFrame = CFrame.new((CFrame.new(y.Position, main.Position)*CFrame.new(0,0,-.1)).p)
working = true
else
y.CFrame = CFrame.new(main.Position)
end
end
wait()
end
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
30 Aug 2014 11:08 PM
I'm having issues exiting the while loop.. is there an alternative? I dunno how to make it a coroutine.. The script does work though!
Report Abuse
Bobobob12 is not online. Bobobob12
Joined: 23 Jan 2008
Total Posts: 5350
30 Aug 2014 11:14 PM
coroutine.wrap(function()
local main = game.Workspace.Main --where you want to move to
local model = game.Workspace.Bricks --all the bricks you want moved

local working = true

while working do
working = false
for x, y in pairs(model:GetChildren()) do
if (y.Position - main.Position).magnitude > .2 then
y.CFrame = CFrame.new((CFrame.new(y.Position, main.Position)*CFrame.new(0,0,-.1)).p)
working = true
else
y.CFrame = CFrame.new(main.Position)
end
end
wait()
end
end)()

now you can do whatever else you want in the script
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
30 Aug 2014 11:15 PM
It was like lerp or something
Report Abuse
IAmTheRolo is online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
30 Aug 2014 11:16 PM
This is pulled directly from one of my tweening functions I wrote some time ago.

function tweenPartToPart(secondaryPart,mainPart,time)
Spawn(function ()
local secondary_matrix = {secondaryPart.CFrame:components()}
local frames = math.floor(time/0.03)
for index1 = 1,frames do
local new_matrix = {}
main_matrix = {mainPart.CFrame:components()}
for index2 = 1,12 do
table.insert(new_matrix,secondary_matrix[index2]+((main_matrix[index2]-secondary_matrix[index2]))*(index1/frames))
end
secondaryPart.CFrame = CFrame.new(unpack(new_matrix))
wait(0.03)
end
secondaryPart:Destroy()
end)
end

secondaryPart is the part you want to move, mainPart is the part you want secondaryPart to move to, time is how long it takes for secondaryPart to get to mainPart. What is really nice about this is that it also mimics rotation, and rather than saving the mainPart's CFrame beforehand, it will continuously reference it in the loop, so the mainPart can be moving and the secondaryPart will follow it as well.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
30 Aug 2014 11:19 PM
Thanks rolo! You're like the most helpful person on SH lol.


Everyone else was very helpful too though!
Report Abuse
IAmTheRolo is online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
30 Aug 2014 11:19 PM
Oh, and you can also remove secondaryPart:Destroy() if you don't want the brick to get destroyed once it gets to the mainPart.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
31 Aug 2014 02:35 AM
If you want to see my progress on what i'm attempting to script you can take the tool- (coz opensourcing is cool)

It's mostly done, just a few more things to tweek. Press F to use it btw lol.

http://www.roblox.com/TailedBeastBomb-item?id=175467037
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image