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: Help with CFrames please

Previous Thread :: Next Thread 
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
09 Aug 2016 12:06 AM
That spins it around the world with no goal in mind.
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
lego555444 is not online. lego555444
Joined: 21 Sep 2008
Total Posts: 1383
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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
09 Aug 2016 12:20 AM
local c0,c1=CFrame.new(),CFrame.new()
while wait() do
partb.CFrame=parta.CFrame*c0*c1
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
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
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
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
robloxplayerboy101 is not online. robloxplayerboy101
Joined: 11 May 2012
Total Posts: 562
09 Aug 2016 12:28 AM
have you tried lerp?


Report Abuse
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
09 Aug 2016 12:30 AM
are you gonna try mine or nah
Report Abuse
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
09 Aug 2016 12:30 AM
i did try yours, it didnt work
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
09 Aug 2016 12:31 AM
the most recent one is not what im looking for
Report Abuse
robloxplayerboy101 is not online. robloxplayerboy101
Joined: 11 May 2012
Total Posts: 562
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
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
09 Aug 2016 12:35 AM
thedailyblarg your new code again still flips it around, thank you for your repeated efforts though
Report Abuse
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
09 Aug 2016 12:36 AM
anchore the parts ?
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Aug 2016 12:36 AM
have you tried storing PartB and PartA instead of replacing them?
Report Abuse
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
09 Aug 2016 12:37 AM
The parts are anchored. I dont know what you mean by replacing them.
Report Abuse
BrokenBone is not online. BrokenBone
Joined: 28 Feb 2009
Total Posts: 678
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
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