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

How to add position to a part relative to another part? \\ cframe operations

Hello, I created a levitation script. When the character points up, the levitating object goes up, same with down, left and right. The problem is that in my method, if the char goes behind the object (in world space), the movements become inverted, sinse the scripting is adding worldspaced vector3 to the object position. What I need is to make the object go aways to the Char’s right when I press to go right, and not the world’s right.

So the scrips now is like this:

TargetsBodyPosition.Position = target.Position + Vector3.new(inputX, inputY, inputZ)
-- in a loop, unsing BodyPosition Mover

How should I fix it?

6 comments

0

What are inputX, inputY and inputZ?

0

numbers that vary between -1 and 1 acording to mouse and keyboard input.

0

Well the general idea is that you have to check where the part is based on where the character is. You can do this by taking the CFrame of the char and using PointToObjectSpace(target.Position). This should give you the position relative to the char. Try adding your offset onto that and then converting that back to worldspace.

0

i tried to do this a lot, I swear, but I cant because i get confused

0

Can you chat on the Discord so we can attempt some solutions rather than throwing back and forth comments?

0

ok, im Necro_las#9490

1 answer

✓ Accepted answer

You can fix this by applying the offset Vector3.new(inputX, inputY, inputZ) at the localspace of the part compared to the character.

local offsetToChar = character.HumanoidRootPart.CFrame:PointToObjectSpace(target.Position)
TargetsBodyPosition.Position = character.HumanoidRootPart.CFrame:PointToWorldSpace(offsetToChar + Vector3.new(x, y, z))

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