Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shocks3 damping calculation is wrong? #3228

Open
danmackey opened this issue Feb 13, 2025 · 1 comment · May be fixed by #3229
Open

Shocks3 damping calculation is wrong? #3228

danmackey opened this issue Feb 13, 2025 · 1 comment · May be fixed by #3229

Comments

@danmackey
Copy link
Contributor

I was looking into shocks3 and the logic behind it and I think there is a bug in the damping calculations.

In the original discussion for shocks3 this graph was posted:
Image

I figured that making something to visualize different values would help me understand tuning a bit more.

So I looked at Actor::CalcShocks3 and reimplemented it in Python so I can quickly produce a plot of the same curve.

Here I noticed the same parameters produced a different plot:
Image

I then plotted the original logic that Dohzer suggested:
Image
Image

Out of curiosity, I tried plotting the calculation that's in the game, but without the last d /= v
Image

I assume the goal was to get damping curves like the one that Dohzer posted in the Discord, meaning this is a bug?

Here's the Python code I wrote:

# pip install numpy pandas plotly

from typing import Callable

import numpy as np
import pandas as pd
import plotly.express as px

def ror_shocks3(damp: float, slow: float, split: float, fast: float):
    def curve(v: float):
        v = np.clip(abs(v), 0.15, 20)
        d = damp * slow * min(v, split) + damp * fast * max(0, v - split)
        d /= v
        return d
    return curve

def ror_shocks3_fixed(damp: float, slow: float, split: float, fast: float):
    def curve(v: float):
        v = np.clip(abs(v), 0.15, 20)
        d = damp * slow * min(v, split) + damp * fast * max(0, v - split)
        return d
    return curve

def dohzer(damp: float, slow: float, split: float, fast: float):
    def curve(v: float):
        if v <= split:
            d = damp * slow * v
        else:
            d = damp * fast * (v - split) + (damp * slow * split)
        return d
    return curve

damp = 5000
slow = 0.5
split = 1.2
fast = 0.2

curves = {
    'Shocks3': ror_shocks3(damp, slow, split, fast),
    'Dohzer': dohzer(damp, slow, split, fast),
    'Shocks3 Fixed': ror_shocks3_fixed(damp, slow, split, fast),
}

def calc_curve(curve: Callable[[float], float], title: str) -> pd.DataFrame:
    v = np.linspace(0, 3.5, 100)
    d = [curve(x) for x in v]

    return pd.DataFrame({'velocity m/s': v, 'damping': d, 'curve': title})

curves_df = pd.concat([
    calc_curve(curve, title)
    for title, curve in curves.items()
]).reset_index(drop=True)

fig = px.line(
    curves_df,
    x='velocity m/s',
    y='damping',
    color='curve',
    line_dash='curve',
    range_y=[0, 6000],
    title=f'{damp=}, {slow=}, {split=}, {fast=}',
)

fig.show()
@danmackey danmackey linked a pull request Feb 14, 2025 that will close this issue
@ohlidalp
Copy link
Member

ohlidalp commented Mar 7, 2025

Only a few select mods seem to use shocks3, so this should be applicable. I'm checking it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants