Spring system fixed update

arenoo

Member
I was trying to add a recoil effect to my assault rifle, however when I built the game for mobile platforms the fps was unsurprisingly lower than in editor so the recoil effect is much stronger. After some digging I figured out that the spring system used for arms and gun is being updated in regular Update mode (every frame). I switched it to use FixedUpdate (hardcoded for now) and now the arms start to *vibrate* when I move the character or when I jump. Also I cant find the correct spring system in editor to play around with stiffness, damping etc. Can you please tell me where to find the correct spring component and how to fix the shaking issue?
 
The arms are updated within the Update loop so if you set the spring to a fixed update loop then it's going to jitter and not work correctly. Have you profiled on your target platform? That should indicate what you need to optimize - the spring system itself is really light weight so I doubt that's the bottle neck.

The spring isn't a component - it's an object that is used by components. You can adjust the spring parameters on the First Person Perspective component.
 
My point is that the recoil shouldn't be tied to fps in any way. It should be the same regardless. How do I make the spring system and the arms use fixed update without changing existing code? Is there some kind of a checkbox somewhere in the inspector?
 
Last edited:
The recoil amount isn't tied to the FPS - this is added during the fixed update loop. The recoil spring does update within the Update loop to ensure it smoothly moves with a variety of framerates. If it were updated during FixedUpdate you'd see jitter anytime your FPS doesn't match your fixed framerate (which sounds like what you are seeing).
 
I mean the visual knockback of the rifle, not the actual recoil. In low fps the knockback is much stronger, the rifle scope almost passes through player camera
 
What framerate are you seeing that? I just compared the amount of knockback with the assault rifle and a framerate limited to 20 compared to 60 and they looked to be the same. You won't get the exact same knockback due to the amount of force added at different times.

With that said, I recommend that you set the Min/Max value of the spring so it will prevent it from going too far back. This can be set within the First Person Perspective component.
 
Top