Hello! I’m sure this is some basic stuff but I’m having trouble getting this zombie to move 10 studs RIGHT of the “target position” , no matter the orientation of the target. I need to know how to convert the position. I need to do so without referring directly to the PrimaryPart CFrame because in my real script, I don’t have direct access to the PrimaryPart. Only the position is passed to my move function for specific reasons.
local humanoid = script.Parent.Humanoid
while wait() do
local target = workspace.Dummy.PrimaryPart.Position
local convert = CFrame.new(target) * CFrame.new(0,0,10)
humanoid:MoveTo(convert.p)
end
Use CFrame.RightVector, yep, it’s literally called right vector, there is also CFrame.LookVector which is the front and CFrame.UpVector which is up, and if you want the opposite of those vecors, just slap a minus - next to it, i.e -CFrame.RightVector would be the left vector. Now when you do take the vector of a CFrame, it will give you a Vector3 with a length of 1 stud, so if you want to take the rightVector of that dummy and project where it would be, you simply do: dummy.HumanoidRootPart.Position + dummy.HumanoidRootPart.CFrame.LookVector
and that would be 1 stud to the right of that dummy, if you want any number of studs, just times that vector by the number of studs you want, i.e: dummy.HumanoidRootPart.Position + dummy.HumanoidRootPart.CFrame.LookVector * 10
That would be 10 studs to the right of that dummy, you get it.
“I need to do so without referring directly to the PrimaryPart CFrame because in my real script, I don’t have direct access to the PrimaryPart. Only the position is passed to my move function for specific reasons.”
If I understand correctly, you need the zombie to always be offset 10 studs to the right of the target’s worldly position?
local offset = Vector3.new(10,0,0)
local zombie -- define
local target -- define
game:GetService("RunService").Heartbeat:connect(function() -- a faster loop than wait()
local targetPos = target.Position
zombie:SetPrimaryPartCFrame(CFrame.new(targetPos+offset))
end)
This does not account for orientation. You mention you cannot reference the PrimaryPart of the target, so you will need to pass along the orientation as well as the position.
Oh gotcha,
For this, you’ll absolutely need to know the orientation of the target, somehow, someway.
Your system needs to be designed in such a way as to send the CFrame instead of the Position. Or at the very least, send both the Position and the Orientation of your target part.
Remember, you can always derive positional data from a CFrame.
CFrame.new(0,0,0).p -- equal to Vector3.new(0,0,0)
If you need to convert the Position and Orientation to a CFrame, you can say