I'm struggling with figuring out a few aspects of the script, hope anybody can shine some light onto it. Also hope I can explain it well enough.

Understeer:

When the car is understeering, the script should take appropriate action. Means the following for these two situations:

- Force feedback: Grip drops, so the steering wheel should be lighter.
- Stability Control: Understeer, so a wheel should be braked to correct for this.

The "action" side works well, but the "detect" side is crude and inaccurate.

Currently I do the following to figure out if the vehicle is understeering:

```
// Gather data
float speed = ENTITY::GET_ENTITY_SPEED(g_playerVehicle);
Vector3 vecNextSpd = ENTITY::GET_ENTITY_SPEED_VECTOR(g_playerVehicle, true);
Vector3 rotVel = ENTITY::GET_ENTITY_ROTATION_VELOCITY(g_playerVehicle);
// Translate rotation around Z into a forward vector, rotated by how fast it is turning.
Vector3 rotRelative{
speed * -sin(rotVel.z), 0,
speed * cos(rotVel.z), 0,
0, 0
};
// Combine speed vector and rotation vector to get an average vector containing both speed and rotation.
Vector3 vecNextRot = (vecNextSpd + rotRelative) * 0.5f;
// Where I expect the car to be from steering input
Vector3 vecPredStr{
speed * -sin(avgAngle / g_settings.Wheel.Steering.SteerMult), 0,
speed * cos(avgAngle / g_settings.Wheel.Steering.SteerMult), 0,
0, 0
};
// Actual understeering angle is the difference between what we expect from input versus how the car is turning
float understeerAngle = GetAngleBetween(vecNextRot, vecPredStr);
float dStrSpd = Distance(vecPredStr, vecNextSpd);
float dStrRot = Distance(vecPredStr, vecNextRot);
float dSpdRot = Distance(vecNextSpd, vecNextRot);
// Only understeering if the steering vector is outside the forward and rotational vectors,
// to account for oversteer and rear wheel slip angles
if (dStrSpd > dSpdRot) {
// Finally apply a minimum amount of understeer to do something.
if (abs(understeerAngle) > deg2rad(g_settings.DriveAssists.ESPUnderMin)) {
espUndersteer = true;
}
}
```

This works well, until the vehicle is transitioning from one rotation direction to another:

- The steering vector "leads", and is outside the range. This can be filtered out by looking if both vectors are on the same side of the speed vector.
- The rotation vector catches up, and goes past the speed vector, and is between the steer vector and speed vector now. Here, understeer is detected.
- The rotation vector has caught up and the rotation-speed vectors now are "around" the steer vector again, no understeer.

Images:

- Blue = speed vector
- Green = steer vector
- Red = rotation+speed vector

Normal understeer.

Understeer during transition - which should not be registered. All the data looks the same as normal understeering, aside from the fact the weight is still shifting.

Anybody has an idea on how to detect and filter for this?