Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How could i make an unanchored object float?

Asked by 5 years ago

To be more specific, I don't want it to just float (i could use BodyPosition) but I also need it only to float on the Y-axis but keep updating its X and Z axis. Which means that if the object moves to the right it won't immediately move back to the last position. I've tried this:

script.Parent.Changed:Connect(function()
    local XPosition = script.Parent.Position.X
    local ZPosition = script.Parent.Position.Z
    script.Parent.Position = Vector3.new(XPosition, 13.376, ZPosition)
end)

and it didn't work

0
Why can't you anchor it? EzraNehemiah_TF2 3552 — 5y
0
I have some welded parts, when i anchor it, they dont move along with the object SuperBeeperman 30 — 5y
0
I said to anchor all your parts in my answer. EzraNehemiah_TF2 3552 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

CFrame

CFrame is a data type that represents the part's position and orientation (rotation).

local part = workspace.Part

part.CFrame = CFrame.new(0,10,0) --Moves part to 0, 10, 0.
wait(3)
part.CFrame = part.CFrame * CFrame.Angles(math.rad(45), math.rad(45), 0)
--Same position, change the rotation.

Welds and CFrame

Any parts connected by welds or other attachments will all move as one unit when you change the CFrame of one of the parts. You can use this with your welded parts to move them all as one. Just note that the part you're moving is going to act as the "center" of everything you're moving. If you move a part on the way right and change the CFrame of that, the part on the way right will be teleported to that position and orientation. All the other parts connected will move in relation to part on the right.


Final Product

You can anchor all your parts now and they will still move together. No body movers needed.

script.Parent.Changed:Connect(function()
    local XPosition = script.Parent.Position.X
    local ZPosition = script.Parent.Position.Z
    script.Parent.CFrame = CFrame.new(XPosition, 13.376, ZPosition)
end)


Hope it helps!

0
This doesn't work. I've tried CFrame million times before but it just keeps bouncing, thanks for taking the time to write all of this out though :) (vid: https://gyazo.com/397a0a8343015616537bb52c9db71071) SuperBeeperman 30 — 5y
1
Anchor all the parts, the weld will still move together. I said specifically in my answer under final product to anchor all the parts. In your video, you clearly did not anchor anything. EzraNehemiah_TF2 3552 — 5y
0
you could also use a body position theking48989987 2147 — 5y
0
LordDragonZord i think you did not take that time to read through it. a weld does not work when something is anchored SuperBeeperman 30 — 5y
Ad

Answer this question