I’m trying to make a following spotlight, we were thinking of using motor6ds to make it move but we had no idea how to make it follow a person. It’s going to emit a beam texture and a spotlight on the head.
I need some help, thanks!
I think the first step would be to find the angle to the player.
You might have to find two angles the up and down and left and right then tilt the motor6d using that.
I have never really understood Motor6ds so maybe it might be a little different. However the math is prettty simple.
local function GetYaxis(center, lookat) return math.atan2(lookat.X - center.X, lookat.Z - center.Z) end
The code is only for the left and right Y Axis
I am not sure if Motor 6ds follow orientation like movement. So I am not sure if the code will be applicable.
You can also use something like this, You might have to tweak some things but this should work.
local char = --define character
local camera = --Part that you want to face player
while wait() do
camera.CFrame = CFrame.new(camera.Position, char.HumanoidRootPart.Position)
end
In this case I would use the HingeConstraint | Roblox Creator Documentation to rotate the camera. Make sure that it is set up as a Servo
so you can then edit the HingeConstraint | Roblox Creator Documentation. I am unsure about the math to calculate the rotation however.
Thank you everyone for the help! I’ll open this thread for a while, feel free to give better solutions!
Motor6D is much better than hingeconstraint though.
If you despise anything that can relate to physics things from constraints/etc:
Just cframe it.
You might want to try CFrame.lookAt as well
All you do is get the origin c0 then multiply it by the angle CFrame which faces the player?
Is this correct? Am I supposed to unanchor the model?
I got an error.
- Don’t use
while wait() do
for this situation, RunService’s events are more suitable here. - OP wanted to move the arm together with the head, and they’re using Motor6Ds too, so setting the CFrame of the model is a final resort probably.
-
CFrame.new(pos, lookAt)
is deprecated, useCFrame.lookAt()
instead.
Model is not a basepart. You need to use something actually in the model.
For the character you need to fetch it from game.Players.PLAYERNAME.Character
and for the camera, you should be setting the model’s PrimaryPart’s CFrame instead.
Yes make sure that the light is on the front face, because CFrame.lookat will look at it from the front face.
If you want to use CFrame.lookAt
then just know that it will rotate the camera from it’s center of mass. The best way you can avoid this is to do these steps:
- Place the main camera part inside of its own Model | Roblox Creator Documentation object
- Create an invisible part, anchor it, and place it in the camera parts model.
- Position the part in-between the arms that attach to the camera and in-line with the center of the camera part
- Orient the part so that it’s front face is facing the direction you want the camera to point
- Set the Model | Roblox Creator Documentation of model the camera part and the invisible part are in to the invisible part
- Unanchor the camera part and use a WeldConstraint | Roblox Creator Documentation to weld it to the invisible part
6.1. Set the WeldConstraint | Roblox Creator Documentation to the camera part
6.2. Set the WeldConstraint | Roblox Creator Documentation to the invisible part
Then you can use set the invisible bricks cframe using CFrame.lookAt and the camera part with move with it.