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

How do I CFrame relative to a part's current position?

Asked by
P100D 590 Moderation Voter
9 years ago

All the wiki article says is about moving parts to a position. How about, say, moving a part 10 studs up?

1 answer

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

It's as simple as this:

(Example script) - This would move the part relative to another parts location:

Part1=script.Parent
Part2=game.Workspace.Part2
Part1.CFrame=CFrame.new(Part2.Position.X,Part2.Position.Y+10,Part2.Position.Z) --This would move "Part1"  exactly 10 studs above "Part2".

(Example script 2) - This would move the part relative to its location

Part1=script.Parent
Part1.CFrame=CFrame.new(Part.Position.X,Part.Position.Y+10,Part.Position.Z) --This would move it exactly 10 studs above it's previous location.

So basically, you just use Position.X , Position.Y , and Position.Z to get the Parts positions, then you subtract or add to get it to where you want. Anyways, if you have any questions, please leave a comment below. Hope this helped :P

1
Inefficient. You can simply multiply a CFrame by another CFrame which is "adding" them together. It will return the combined CFrame SurVur 86 — 9y
0
He's not an expert scripter, don't worry about efficiency. He's learning the basics, so it doesn't really matter. dyler3 1510 — 9y
Ad

Answer this question