Make a flashlight shake while the player moves

I’ll show you code I use for realistic movement deviation in my game LANDNAV.

You wont be able to copy this code and have it work. But it does something similar to what you have described, so you can look at the code and once you understand how it is working, you can probably use a similar idea for your flashlight.

What this code does is add slight variations to the players control rotation while they are moving. With a very small value it is basically like the character “shakes” while moving. You can change the magnitude and frequency of the shake to suit your own needs.

The basic idea is that you are making this random float value that only happens while some condition is true.

For your flashlight that might be adding some random values to specific axes of the local rotation.

Here is the code:



Here is how we know when player is moving, you can check this on a timer or tick, or from your movement input:

and the guts of the Do While Special, a super handy macro:

1 Like