|
| 09 Aug 2016 12:01 AM |
Lets assume I have Part A and Part B. Part B is always going to be in direct proportion to Part A. I want to move Part B around whenever part A moves. So if Part B is slightly above part A and rotated 40 degrees, and I rotate part A 180 degrees, part B should not be slightly below and rotated -40 degrees.
This is perfectly done with welds(so you get the picture of what I'm aiming for), but I want it done without welds, CFrames only.
I figured getting the difference between part A and B and then applying it to Part B whenever Part A moves sounds right, but I dont know how to do that. Anyone have any ideas? |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:03 AM |
Since this is how welds work
c0 = Part0.CFrame:inverse() * Part1.CFrame
then perhaps
yes?
while wait() do partB.CFrame = partB.CFrame:inverse() * partA.CFrame end |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:06 AM |
| That spins it around the world with no goal in mind. |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:09 AM |
local offsetPosition = CFrame.new(PartA.CFrame.p - PartB.CFrame.p) local offsetRotation = (PartA.CFrame-PartA.CFrame.p):inverse() * (PartB.CFrame - PartB.CFrame.p)
while wait() do
PartB.CFrame = PartA.CFrame * offsetPosition * offsetRotation
end
--if position glitches, swap parta and partb in the top |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:17 AM |
So you want B to orbit A?
Check out my game: https://www.roblox.com/games/262422056/_ |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:18 AM |
No he wants it to follow PartA as if it was welded to it.
My script should work hopefully |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:20 AM |
local c0,c1=CFrame.new(),CFrame.new() while wait() do partb.CFrame=parta.CFrame*c0*c1 |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:22 AM |
local a = CFrame.new(0,1,0)*CFrame.new(0,math.rad(40),0) while wait() do partb.CFrame=parta.CFrame*a end |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:26 AM |
| thedailyblarg, that looks more like the code i was expecting to see, but it doesnt quite work perfectly, and i never learned CFrames well enough to fix the problem |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:27 AM |
local a = CFrame.new(0,1,0)*CFrame.Angles(0,math.rad(40),0) while wait() do partb.CFrame=parta.CFrame*a end
-- i am so asleep today |
|
|
| Report Abuse |
|
|
| |
|
|
| 09 Aug 2016 12:29 AM |
| I don't understand lerp, and I don't know the rotation/position differential myself, it can be anything. |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:30 AM |
| are you gonna try mine or nah |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:30 AM |
| i did try yours, it didnt work |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:30 AM |
local PartA = workspace.PartA local PartB = workspace.PartB
local offsetPosition = CFrame.new(PartB.CFrame.p-PartA.CFrame.p) local offsetRotation = (PartA.CFrame-PartA.CFrame.p):inverse() * (PartB.CFrame - PartB.CFrame.p)
while wait() do
PartB.CFrame = PartA.CFrame * offsetPosition * offsetRotation
end
--this COMPLETELY works
proof link: https://i.gyazo.com/74188266134ac623e7d01e5ebe212782.gif |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:31 AM |
| the most recent one is not what im looking for |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:32 AM |
when you rotate the first part (to 180 degrees), do this with the second part:
part.CFrame = part.CFrame:lerp(partwith180degreesofrotation.CFrame,.3)
change the .3 to dampen/amplify the speed it takes for it to reach 180 in one go if you do this in a loop, it will slowly put it into position, but since we are only doing it once, it should work for you
if i got your instructions wrong, can you simplify your question for me? i'm very bad at understanding.
|
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:33 AM |
| thedailyblarg yours is still not working. i run the script and each time the PartB switches positions before repeatedly being set to that new wrong position |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:34 AM |
anchor partb
and i fixed the position glitch this is different code
local offsetPosition = CFrame.new(PartB.CFrame.p-PartA.CFrame.p) local offsetRotation = (PartA.CFrame-PartA.CFrame.p):inverse() * (PartB.CFrame - PartB.CFrame.p)
while wait() do
PartB.CFrame = PartA.CFrame * offsetPosition * offsetRotation
end |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:35 AM |
| thedailyblarg your new code again still flips it around, thank you for your repeated efforts though |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:36 AM |
| I dont think I need to use lerp for this, it should be simple enough to find the difference in positions and rotations and then apply them whenever Part A moves. |
|
|
| Report Abuse |
|
|
| |
|
|
| 09 Aug 2016 12:36 AM |
| have you tried storing PartB and PartA instead of replacing them? |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:37 AM |
| The parts are anchored. I dont know what you mean by replacing them. |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 12:38 AM |
| I should provide more detail: Your code works in keeping the Part B away from Part A repeatedly, however when it first runs it gets the wrong differentials and thus always resets it to the wrong proportion |
|
|
| Report Abuse |
|
|