How would I go about making a flashlight follow where my camera is looking in first person and have it tween to the camera’s look position. I have tried many solutions such as Raycasts, Unit’s, ScreenPointToRay/ViewPortToRay and nothing works. I am doing this on the client because I do not want the camera to show for everyone and I want this to work for all devices not just PC with Mouse.Hit and stuff.
I sadly can’t find any solutions, I have tried many solutions.
Incase your wondering I want this to be like Nico’s next bots camera where the flashlight slowly moves towards the cameras facing point and only shows cliently.
assuming you have your flashlight premade do this:
make sure the flashlight is welded to a sort of main part (sort of like the middle of it)
also make sure its front is facing the direction of the light emission
local flashlight = inserttemplatehere
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(dt) -- dt is delta time (time in between frames)
flashlight.Main.CFrame = Workspace.CurrentCamera.CFrame -- assuming you named the main part "Main"
basically what it does is it set the flashlights cframe to the cameras cframe (position and direction it should be looking) every frame.
to get that loose motion you are looking for, look into tweening the cframe every frame by either the delta time (dt) or like half a second
My flashlight module might have what your looking for. It’s client sided, follows your camera. And works on all devices. I have a script you can use that makes the flashlight work. The flashlight is based on both Nico’s Nextbots and Apeirophobia. Mark this as solution if it works!
Oh yeah and if you want the tween slower, everything is configurable INSIDE the module. Just configure the time in seconds in tween info, the time in seconds are currently set to “0.11”