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)
EXAMPLE: Target dummy was rotated, zombie should move to red area.
Is the HumanoidRootPart in the zombie unanchored?
Usually, orientation is completely automatic when using MoveTo().
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.”
Then pass the CFrame instead of the position, CFrame holds position and ortientation. There is no other way.
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
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.
How is that gonna be to the right of the dummy? You are positioning relative to world, and that would almost never be to the right of the dummy.
The code I gave will put the zombie 10 studs to the right of the target in World Coordinates. That is, an offset of 10 studs on the world’s x axis.
Forgive me if I misunderstood the prompt.
Using the “CFrame.new(targetPos+offset)” method with MoveTo:
When I rotate the dummy, the zombie should follow and move right of him.
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
CFrame.new(part.Position)*CFrame.Angles(part.Orientation.X, part.Orientation.Y, part.Orientation.Z)