NoiseSettings for weapon recoil

I’m using a POV Cinemachine camera for an FPS I’m working on and I’m having trouble getting recoil working the way I want. The current noise goes either positive or negative on the X axis, but I was hoping to have the impulse use the absolute value of the x rotation, but leave the y rotation alone. That way the gun recoil always tilts the camera up, but jiggles side-to-side just fine.

If you’re using Impulse, then you can make the signal happen in camera-local space by passing the camera forward vector to GenerateImpulse(). That direction will be considered to be “down” in signal space, so a signal with rotation around the x axis should make the camera shake up and down. What signal are you using?

6188358--678423--upload_2020-8-10_10-54-45.png

I don’t want it to shake up and down though, just up. Shaking left and right is fine, but I want absolute value of noise on the x axis so it only shakes up. For example, look at the type of weapon sprays in Counter Strike to get an idea of what I mean: CS2 Spray Patterns & Recoil Compensation for All Guns | Profilerr

Did you try using a fixed signal as the source? That way you can draw the exact curve you want:

6191223--678909--upload_2020-8-11_7-6-17.png

6191223--678912--upload_2020-8-11_7-6-45.png

When I used the fixed signal it changed the vcam’s position, not rotation.

You can make a variant of the FixedSignal that outputs a rotation noise instead of a position noise. Inherit from CinemachineFixedSignal and override GetSignal().

I’ve attached a script that does exactly that. Drop it in your assets and it will be available in the menu

6192768--679101--upload_2020-8-11_14-0-53.png

6192768–679104–CinemachineFixedRotationSignal.cs (1.2 KB)

1 Like

Thank you! I had no idea you could extend the signal class like that. For anyone reading this in the future, I updated the GetSignal() method to this:

rot = Quaternion.Euler(new Vector3(
                AxisValue(m_XCurve, timeSinceSignalStart),
                (Mathf.PerlinNoise(Time.time, Time.time) - .5f) * 2 * YawNoiseAmplitude,
                AxisValue(m_ZCurve, timeSinceSignalStart)));

This way it always tilts the camera up based on the x axis curve, but sways side-to-side on the y axis based on random noise. It works great for weapon recoil.

2 Likes