I’m trying to move a part that functions as a camera in front of the player every time an event is triggered, but it will spawn in random spots around the player undesirably. I have tried solutions on the dev forum and looking through the internet to no avail.
Here is the part I’m having trouble with:
cam.Position=head.Position*Vector3.new(0,0,-5)
because this vector is 5 studs in the negative z direction which doesnt automatically rotate with the player
you can get the direction the head (or any part) is looking with .CFrame.LookVector which gives a vector 1 stud in front, so you multiply by a scalar to get that many studs in front
cam.Position = head.Position + head.CFrame.LookVector*5
edit: also adding vectors is the same as adding numbers, but adding numbers is the same as multiplying cframes
1 Like
CFrame version of @happya_x’s solution
cam.CFrame = head.CFrame * CFrame.new(0,0,-5)
CFrames are a joy when you understand how to use them (which really isn’t a given…)
Thanks, you’re a real life saver. I’m not that good with CFrames.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.