Progressive recoil

I made a progressive recoil with muzzle climb.

1 Like

Cool addition! :star_struck:

If you allow my constructive remarks:

  1. You are using a lot of “magic numbers” in your code - constant values of which you know right now what they do, but future you or other people might have trouble working with your code. Variables with clear names are recommended, exported where it makes sense.

  2. I’d advise against the way you use Lerp, even though Bram showed it like this. Using constant Lerp ratio arguments in _process, you might end up getting very different results for low or high frame rates.
    See also Godot Interpolation tutorial.
    In general, when lerping a value, it is good practice to have a clear idea for what the start and end value (A and B in many lerp explanations; they might change with each shot in a recoil scenario) and their progress should be. When updating in _process, the value of delta should be used to keep the progress independent of the frame rate.

Reworked it after added the rifle so it’s more modular, using exposed variables:

image

Now both weapons have their own recoil pattern.

Great job on the exports! Indeed, they are great to customize the weapons.

There’s still some confusion about Lerp. The t argument is not a threshold. It’s a ratio (like a percentage but given from 0 to 1 instead writing it as 0% to 100%) for the progress on the path between A and B. E.g.:

  • If the ratio is 0, the result is A.
  • If the ratio is 1, the result is B.
  • If the ratio is 0.5, the result is exactly in the middle between A and B.

Borrowing from the tutorial linked above:

But I know the confusion was introduced in the code in the lecture, which is a pity in particular because the theoretical explanation in the video was ok. The way Lerp is used in the code does not make too much sense…

Privacy & Terms