CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
563 stars 85 forks source link

Improve bus stop path #1688

Closed kianzarrin closed 1 year ago

kianzarrin commented 1 year ago

image buses follow the red path in the image above. and tend to block the road while stopping particularly when there are multiple buses. it would be better if they followed the black path to get out of the way as fast as possible. if Articulated bus turns too sharp it may block the inner lane so the path should not be too sharp. image

related: https://github.com/CitiesSkylinesMods/TMPE/issues/1020#issuecomment-716743962

kianzarrin commented 1 year ago

image overlay rendered by this mod : https://steamcommunity.com/sharedfiles/filedetails/?id=2883351966

the code will look like something line this:

public static bool Prefix(ref NetLane __instance, float laneOffset, float stopOffset, out Vector3 position, out Vector3 direction) {
    ref Bezier3 bezier = ref __instance.m_bezier;
    position = bezier.Position(laneOffset);
    direction = bezier.Tangent(laneOffset);
    Vector3 sideDir = Vector3.Cross(Vector3.up, direction).normalized;

// NON STOCK CODE START
    const float t1 = .12f;
    const float t2_0 = 0.20f;
    float t2 = t1 + 0.7f / __instance.m_length;
    t2 = Mathf.Max(t2, t2_0);

    float t = laneOffset <= 0.5f ? laneOffset : 1 - laneOffset;
    float d;
    if (t < t1) {
        d = 0;
    } else if(t > t2) {
        d = 1;
    } else {
        d = (t - t1) / (t2 - t1); // from 0 to 1
    }
// NON STOCK CODE END

    position += sideDir * stopOffset * d;
    return false;
}