Hey there, my name is ShieldDevs, you can call me shield. I’m a scripter and a game developer.
So lately I’ve been working on a scary game, “Escape the Unknown”, and I was trying to make a realistic flashlight that’s attached to the head. And I’ve seen a lot of horror/scary games, and the flashlight there is a bit slower, it follows the camera with a bit of slow, smooth movement, it’s in almost all games.
I think there are two possible ways to achieve this effect you’re looking for, the first one would be to use TweenService and the other is you use the CFrame:Lerp() function.
you can look at how the classic flashlight tool works, also making the players head point to their cursor achieves this affect, however the latter is hard to replicate to server smoothly without loosing performance and is mostly just on client.
In the link I provided you can check how to properly use the TweenService as it comes with examples too. CFrame:Lerp() is used within a loop, you give it a goal and then an alpha, the goal would be the CFrame which you would have to calculate, it would need to include the position of the flashlight and it’s rotation (pointing to the mouse), think of alpha as how “snappy” the movement would be, 0.3 works fine.
Yeah, I’ve been moving the head with the cursor, and it kind of does that, but when the player’s FPS is too high, it becomes as if it’s just a normal flashlight. And thank you for your answer, really appreciate it.
Ok I’ll try using Lerping, because I advanced TweenService and I can’t seem to find it useful in this situation, so I’ll look around for Lerping, hopefully it’ll help me reach there. Thank you!
TweenService is indeed useful, it basically allows to get a smooth transition between two things, in this case you can just use TweenService to smoothly interpolate the head’s CFrame.
Infact, BodyMovers could be the way to go around doing this, if you’re going for the effect on the video, using BodyMovers to make the light part follow your character’s orientation and movement could work.
You would tween it like you would tween any other part as it doesn’t matter if its in the head. However, as mentioned above it might be better if you went for BodyMovers as you’d constantly be having to create tweens and play them whereas with BodyMovers, you’d get a more realistic effect (or atleast whatever i’m imagining in my head seems more realistic) and probably easier to implement.
It’s the same thing with BodyMovers, you need to constantly be feeding them the new information for them to be accurate plus they don’t work well with welded parts. I’d rather just use TweenService or CFrame:Lerp() on the Head’s C0.
That can be achieved with TweenService or Lerp, with TweenService as long as the duration isn’t instant and for Lerp as long as Alpha isn’t 1 he’ll achieve that sort of smooth “delayed” motion.
In a renderstepped event or something
You could edit the 0.5 to be lower or higher to get a faster or slower effect respectively
Offset is the cframe offset relative to the camera (so for example offset = CFrame.new(2,-1,3) would make the flashlight 2 studs to the right of the camera, 1 stud down, and 3 studs in front of the camera)
I wouldnt recommend tweenservice because the camera is constantly changing directions and unless your tween is a 60th of a second long it will be super choppy (and when the tween is a 60th of a second long the easing you can usually easily get with tweenservice practically doesnt exist) (its also kinda overkill to have a whole looped fancy movement with all kinds of easing and new threads and stuff taking up performance for an effect youll mostly not even see, especially when it can be done in a single line of code)
You could use bodymovers but in my personal opinion lerping is way easier and more naturally mixes with the non physics camera system