Bug: Func_tracktrains don't respect deceleration speed when moving backwards, stopping immediately
Describe the bug
When you have a func_tracktrain going backwards in a track, firing it the output SetSpeedDirAccel 0 (with properly set up keyvalues!) will make it stop, rather than make it slow down to 0 slowly. Video attached:
https://github.com/user-attachments/assets/dc22fede-c682-4faa-9930-158c6b7389c6
To Reproduce
- Open attached map
- Test with buttons:
- Left button fires
SetSpeedDirAccel 1making the train move forwards - Middle button fires
SetSpeedDirAccel 0slowly stopping the train - Right button fires
SetSpeedDirAccel -1making the train move backwards
- Move the train to the end path_track using the left button
- Press the right button to move the train backwards, and while it's moving try to push the middle button.
- Observe that the train stopped instantaneously, instead of slowing down
Issue Map
Expected Behavior
The train should stop gracefully, not instantaneously
Operating System
No response
I've tried fixing this issue on the 2013 SDK and I did it!
It turns out, whenever the movement is reversed and you want to stop the train, the direction of movement changes (internally in code) since a function SetDirForward(newSpeed >= 0) gets called, this doesn't happen in forward motion because of that greater or equal operator, which only is false on negative newSpeed.
By implementing this if statement we can omit changing the direction for when newSpeed is 0 altogether, and there we go! Issue fixed.
https://github.com/user-attachments/assets/ab2b9ba4-a5d4-4710-8510-382a40e47c94
Also note: Removing the greater or equal operator and changing to just greater than zero it also won't work, as now the entity will have trouble when stopping from forward motion!