Engine icon indicating copy to clipboard operation
Engine copied to clipboard

Bug: Func_tracktrains don't respect deceleration speed when moving backwards, stopping immediately

Open TheEnderek0 opened this issue 1 year ago • 2 comments

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

  1. Open attached map
  2. Test with buttons:
  • Left button fires SetSpeedDirAccel 1 making the train move forwards
  • Middle button fires SetSpeedDirAccel 0 slowly stopping the train
  • Right button fires SetSpeedDirAccel -1 making the train move backwards
  1. Move the train to the end path_track using the left button
  2. Press the right button to move the train backwards, and while it's moving try to push the middle button.
  3. Observe that the train stopped instantaneously, instead of slowing down

Issue Map

trainissuemap.zip

Expected Behavior

The train should stop gracefully, not instantaneously

Operating System

No response

TheEnderek0 avatar Sep 09 '24 20:09 TheEnderek0

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

TheEnderek0 avatar Sep 09 '24 21:09 TheEnderek0

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!

TheEnderek0 avatar Sep 09 '24 21:09 TheEnderek0