CitiesSkylinesMods / TMPE

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

trams/trains are blocked by their own trailer. #1572

Closed kianzarrin closed 2 years ago

kianzarrin commented 2 years ago

This is also a vanilla problem: when segment is updated or TMPE rules are updated, the leading vehicle will go a little bit backwards (because it will reset simulation speed data) while the trailers will not (they will stop immediately). if the vehicle is going fast enough it can get behind its own trailer and get blocked by it.

https://user-images.githubusercontent.com/26344691/168418804-592f2b8c-1d33-4079-a765-a7cde4bcc51c.mp4

https://cdn.discordapp.com/attachments/545066674605391882/965713435935506512/2022-04-18_23-39-26.mkv

Solutions:

kianzarrin commented 2 years ago

Collision check takes place in CarAI.CheckOtherVehicle().

private static ushort CheckOtherVehicle(ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ref float maxSpeed, ref bool blocked, ref Vector3 collisionPush, float maxBraking, ushort otherID, ref Vehicle otherData, Vector3 min, Vector3 max, int lodPhysics)
{
    if (otherID != vehicleID && vehicleData.m_leadingVehicle != otherID && vehicleData.m_trailingVehicle != otherID)

The if condition above only checks one trailer. we need a prefix that checks all trailers.

krzychu124 commented 2 years ago

@kianzarrin watch carefully the clip. Trailers stop immediately, they don't collide with the leading vehicle. It's the leading vehicle moving back and forth

kianzarrin commented 2 years ago

yes. but if I disable collision with its own trailer then the tram can get un-stuck.

kianzarrin commented 2 years ago

it had nothing to do with collision. train/tram was going backward because targetpos was updated.