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.
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.
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
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
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