I’m not sure how to explain this well so I’ll add a drawing at the end.
Let’s say there is a position 5 feet away from a player. I want to move the position 30 degrees to the left and maintain the 5 feet. How would I do that? (It also would not rotate as the player looks around.)
Someone probably has a more elegant solution but one way to do it is similar to how you rotate a door on its hinge :
local pivot = CFrame.new(0,0,0)
local Distance = 10
local Angle = 30 --- 30°
local Offset = CFrame.new(0,0,Distance) --- offset away from pivot (un-rotated)
local Rotation = CFrame.Angles(0, math.rad(Angle),0) ---Rotation using CFrame.Angles
local NewPositoin = (pivot * Rotation * Offset).Position ---- calculate CFrame then just get the position if you want to
Here it is nicely put into a function:
local function RotatePointAtDist(Point, Angle, Dist)
local Rotation = CFrame.Angles(0, math.rad(Angle),0)
return (CFrame.new(Point) * Rotation * CFrame.new(0,0,Dist)).Position
end
game.Workspace.Part.Position = RotatePointAtDist(Vector3.new(0,0,0),30, 5 )
Did a little research, and if anyone was wondering this is how you can do the pretty much same thing as above but using sin and cos:
local function RotatePointAtDist2( Origin, Angle, Dist)
local Point = Origin + Vector3.new(0,0,Dist)
local S, C = math.sin(math.rad(Angle)), math.cos(math.rad(Angle))
local X = (Point.x - Origin.X) * C - (Point.Z - Origin.Z) * S + Origin.X
local Z = (Point.x - Origin.X) * S + (Point.Z - Origin.Z)* C + Origin.Z
return Vector3.new(X, Origin.Y, Z)
end