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 » Scripters
Home Search
 

Re: Moving a Part relative to another Moving Part

Previous Thread :: Next Thread 
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 08:34 AM
How can I move a Part relative to another moving Part?

Here's an example of what I mean:
I have a semi-transparent Part that floats from left to right (currently using leap()).
I want to have another Part inside that semi-transparent Part that moves up and down.

So basically, Part1 moves left and right, but Part2 moves up and down and moves with Part1 too.

Hopefully I've explained this well enough.
Any help or advise would be greatly appreciated.
Report Abuse
128Gigabytes is online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
13 Feb 2016 08:41 AM
local part0 = Instance.new("Part", game.Workspace)
part0.Anchored, part0.BrickColor, part0.CFrame = true, BrickColor.new("Bright red"), CFrame.new(0, 10, 0)
local part1 = part0:clone()
part1.BrickColor, part1.Parent = BrickColor.new("Bright blue"), game.Workspace

while true do
for x = 1, 16, 0.5 do
part0.CFrame = (part0.CFrame + Vector3.new(0.5, 0, 0))
part1.CFrame = (part0.CFrame + Vector3.new(0, x, 0))
wait()
end
for x = 16, 1, -0.5 do
part0.CFrame = (part0.CFrame - Vector3.new(0.5, 0, 0))
part1.CFrame = (part0.CFrame + Vector3.new(0, x, 0))
wait()
end
end
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 08:58 AM
@128Gigabytes

Thanks for your suggestion, but unfortunately it doesn't work as I need it to and I can't figure out how to get it to work.
Basically, I now have a Part, Part0. It moves with the Player's Camera - so basically it always appears in the centre of the screen.
I need Part1 to move back and forth on Part0.

The problem with your suggestion at the moment is that the Part moves strictly on a given axis, rather than the axis of the second Part, if that makes sense.

Can WorldSpace or LocalSpace, or something like that, help me does this?
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
13 Feb 2016 09:00 AM
Yes, those are exactly what you wanna use when it comes to relative movement. But since I'm really bad at math I can't actually explain how '~'
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 09:20 AM
I managed to work something out, but the movement of Part1 is not very smooth - it kind of jumps about when Part0 moves.


while true do
for x = 1, 10, 0.5 do

objectSpace = CFrame.new(x, 0, 0)
local worldSpace = part0.CFrame:toWorldSpace(objectSpace)
part1.CFrame = worldSpace
wait()
end
for x = 10, 1, -0.5 do

objectSpace = CFrame.new(x,0, 0)
local worldSpace = part0.CFrame:toWorldSpace(objectSpace)
part1.CFrame = worldSpace
wait()
end
end


Can anybody offer a suggestion to make sure Part1 keeps us with Part0 and prevent the unsmooth movements?
Any help or advise would be greatly appreciated.
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
13 Feb 2016 09:23 AM
This is the fastest you can make it. This will run the loop every single time the game renders a frame:

while game:GetService("RunService").RenderStepped:wait() do
for x = 1, 10, 0.5 do

objectSpace = CFrame.new(x, 0, 0)
local worldSpace = part0.CFrame:toWorldSpace(objectSpace)
part1.CFrame = worldSpace
wait()
end
for x = 10, 1, -0.5 do

objectSpace = CFrame.new(x,0, 0)
local worldSpace = part0.CFrame:toWorldSpace(objectSpace)
part1.CFrame = worldSpace
wait()
end
end
Report Abuse
BlueKeyblades is not online. BlueKeyblades
Joined: 11 Oct 2014
Total Posts: 220
13 Feb 2016 09:28 AM
You could use your CFrame strategy, and make is smoother using Welds.

[Work not tested, not bested.]
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 11:02 AM
@BlueKeyblades

How could I use Welds to make it smoother?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 11:16 AM
Could the use of BodyMovers make it smoother?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 11:53 AM
Does anybody know how to make it smoother?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
13 Feb 2016 12:25 PM
Does anybody have an idea?
Report Abuse
BlueKeyblades is not online. BlueKeyblades
Joined: 11 Oct 2014
Total Posts: 220
27 Feb 2016 06:00 PM
Weld the two parts, they will be in the position relative to eachother and their C0 and C1, from them adjust those to make smooth, relative movement

[Work not tested, not bested.]
Report Abuse
TigreBlood is not online. TigreBlood
Joined: 31 Jul 2011
Total Posts: 1107
27 Feb 2016 06:20 PM
for x = 1, 10, 0.05 do
Report Abuse
128Gigabytes is online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
28 Feb 2016 03:20 AM
https://m.youtube.com/watch?v=dqyJk0w2AY0

Also the person who said while game:getService("RunService").renderStepped:wait() do is as fast as you can make it and will run every frame

Theres a few reasons that isn't true
1.You can run it faster by doing while true do, the wait inside the for loop that is just for smoothing the CFrame will stop the script from crashing.
2.You are calling :getService() which is a method (Aka just a fancy function) every time the loop runs, it would be faster to have a local reference to RunService.renderStepped
local renderStepped = game:getService("RunService").renderStepped
while (renderStepped:wait()) do
end
3.It won't run every render frame because the loop might (And in this case always will) already be running when another frame renders.
If you connect an event to it it will run every frame regardless of if it is already running.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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