Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

only using the position when using ToWorldSpace/ToObjectSpace?

I have a script that moves a part to a specific CFrame relative to another parts CFrame. this works well except for one thing, I want to be able to ignore rotation and only have the part maintain its position instead, here's the script:

local pos = script.Parent.Part.CFrame:ToObjectSpace(script.Parent.Part2.CFrame)

while true do
	wait()
script.Parent.Part2.CFrame = script.Parent.Part.CFrame:ToWorldSpace(pos)
end

I tried replacing all CFrames with position, but vector3 is not a valid member of toworld/toobject space.

2 comments

0

I think :vectorToWorldSpace(Vector3) will help you, it will offset the position and ignore the rotation.

0

Or maybe you can use :pointToWorldSpace() depend on your problem.

1 answer

✓ Accepted answer
local pos = script.Parent.Part2.Position - script.Parent.Part.Position

while true do
	script.Parent.Part2.Position = script.Parent.Part.Position + pos
end

The relative position of part two is the position that you add to part one such that the result is part two's position. Therefore, the relative position is simply the position of part two minus that of part one.

1 comment

0

excellent! this is exactly what I needed, thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.