I’m working on a horror game as a side project for fun and need a flashlight mechanic.
Making a normal flashlight that just sticks to where the player looks is an option, but i would love something more unique.
How would i go about recreating this mechanic?:
(Credit: CHORDOSIS - AdamDubiGames)
As you can see, the flashlight is slightly overshooting where the Cursor is going.
I have no clue where i would start to recreate this effect, Could you help?
Not sure exactly how you would do this, but you know how the minecraft characters look when you look around? there’s like a direction your character is facing, and only when you look a certain amount to the left or right of that direction it changes based on how much you move it past. I’m assuming you want to replicate that effect, the flashlight being character direction? I’d have a value for FlashlightRotation, which would be a number between 0 and 359, have something that can get a rotation value like that from the direction of your mouse, then check the differences between the two, and if it’s more than a certain amount in one of the directions, move it. Would have it check every frame or something. Think of the rotation value as Y axis rotation, really. As for checking which direction it’s different in, you would, for one direction, add the difference between one value and 0 and the other value and 360, and for the other direction, just the direct difference. Figure out which side means what. Sorry if this is confusing, but hopefully it helps at least some.
The best way I would go about this, would be using something called Raycasting. To put it in simple terms, Raycasting is a very useful system that allows for many advanced functions such as, making monster vision/NPC vision. What Raycasting does behind the scenes is, whenever called upon, shoots an invisible “Ray” in a given direction. That Ray, then can be used for detections, and other fancy systems. Long story short, I think you would be best off using Raycasting. If you need more info on it, here’s the official developer documentation (as I’m pretty terrible at explaining things ):