Getting Offset of Part with Position and Rotation

I want to get the offset of a part while accounting for its rotation. I have tried using ToWorldSpace() and ToObjectSpace() but I have had little success. I want to offset a part to put it about 15 studs in front of where it is no matter what the orientation is. Thanks for any help and sorry if this is unclear.

1 Like

Is this what you are trying to do?

part.CFrame = CFrame.new(part.CFrame.Position) * CFrame.new(0, 0, -15)

for Positions, you do this:

Part.Position = Part.Position + Vector3.new(0,0,0) -- Your Position Offset

For Orientation, its similar:

Part.Orientation = Part.Orientation + Vector3.new(0,0,0) -- Orientation Offset

This is another Good Example

Im not quite sure, I want to get the offset of the position, but while accounting for rotation.

Then i recommend Following @mniao’s Example

1 Like

You seem to have two problems.

Here’s how you would do this:

part.CFrame = CFrame.new(part.CFrame.Position) * CFrame.new(0, 0, -15)

As for this

You would use CFrame:ToObjectSpace(), like so:

local centerCFrame = CFrame.new()
local secondCFrame =  CFrame.new()

print(secondCFrame:ToObjectSpace(centerCFrame)) --> Prints offset from CenterCFrame
1 Like

I don’t quite understand what the centerCFrame and secondCFrame should be in my example since I only have 1 part

centerCFrame is the CFrame the offset will be based from, it’s the center point, and secondCFrame is the CFrame of the part you want to get the offset from centerCFrame.

EXAMPLE:

local centerCFrame = CFrame.new(5, 0, 3)
local secondCFrame = CFrame.new(10, 0, 5)


print(secondCFrame:ToObjectSpace(centerCFrame)) --Prints (-5, 0, -2), the exact difference from the centerCFrame and secondCFrame aka the offset
1 Like

My issue is with the secondCFrame part because it doesn’t actually exist yet

By infront, you mean in the direction which is facing or a given axis?

if its an axis then easy fix

part.CFrame += Vector3.new(5,0,0)

otherwise

part.CFrame += part.CFrame.LookVector * 15
1 Like