I have recently been using CFrames, but have been having trouble getting it to work properly. I’m using CFrame.lookAt, but I can’t get the side of the the part in question to face the desired point(Its currently the front). here’s the script:
script.Parent.CFrame = CFrame.lookAt(Vector3.new(0,10,0),Vector3.new(0,0,0))
How can I get a different face to look at the specified point?
hey there i believe you’re trying to make the part look at another part, don’t confuse yourself, it’s as simple as this!
script.Parent.CFrame = CFrame.new(Vector3.new(0,10,0),Vector3.new(0,0,0))
this code makes the said part looks from the first position towards the second position.
Here are some examples on how you would get a certain side of a part to face a certain direction.
Not the most efficient way to do it by any means, but it works:
-- Front side facing target
local cf1 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
-- Back side facing target
local cf2 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
cf2 = CFrame.lookAt(cf2.Position, cf2.Position - cf2.LookVector, cf2.UpVector)
-- Right side facing target
local cf3 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
cf3 = CFrame.lookAt(cf3.Position, cf3.Position - cf3.RightVector, cf3.UpVector)
-- Left side facing target
local cf4 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
cf4 = CFrame.lookAt(cf4.Position, cf4.Position + cf4.RightVector, cf4.UpVector)
-- Top side facing target
local cf5 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
cf5 = CFrame.lookAt(cf5.Position, cf5.Position - cf5.UpVector, cf5.LookVector)
-- bottom side facing target
local cf6 = CFrame.new(Vector3.new(0,10,0), Vector3.new(0,0,0))
cf6 = CFrame.lookAt(cf6.Position, cf6.Position + cf6.UpVector, -cf6.LookVector)
Hope this helps!
Nope, that doesn’t seem to do anything at all.
Well I tested it on my end and it worked,
So there’s nothing more I can really do.
Hope you figure it out!
Edit: Just to make sure, if you wanted the right side of a part to face the target, your script would look something like this:
local position = Vector3.new(0,10,0)
local target = Vector3.new(0,0,0)
script.Parent.CFrame = CFrame.lookAt(position, target)
script.Parent.CFrame = CFrame.lookAt(
script.Parent.CFrame.Position,
script.Parent.CFrame.Position - script.Parent.CFrame.RightVector,
script.Parent.CFrame.UpVector
)
Written in the form your example showed.
Can’t test this one out myself so its all up to you now.
Edit 2: better code format
Studying this might help. It certainly did for me.
Got you
local currentPos = script.Parent.Position
local desiredPos = Vector3.new(0, 15, 0)
local whichFace = Enum.NormalId.Front -- change to whatever face you want
local inVector3Form = Vector3.FromNormalId(whichFace)
script.Parent.CFrame = CFrame.lookAt(currentPos, desiredPos) * CFrame.Angles(0, math.pi/2, 0) * CFrame.Angles(math.asin(inVector3Form.X), math.asin(inVector3Form.Z), math.asin(-inVector3Form.Y))
Nice work, Just what I needed. Big thanks for your help.