When the tank hits the car, on_entitiy_damaged will be triggered (event.entity: the car, event.cause: the tank). From the perspective of the tank, I can see the car in front; from the perspective of the car, the tank is in front. I then use tank.prototype.weight and tank.speed as well as car.prototype.weight and car.speed to calculate the bounce speeds of both vehicles. Then I set tank.speed to and car.speed to the respective bounce speeds. I log tank.speed in various places, and the same negative speed is displayed all the time, until the end of the event handler.
Next, on_entity_damaged will be triggered again, but this time the tank is both event.entity and event.cause, so I quit immediately. The log shows that the tank still has the same speed as when the event was triggered for tank+car. However, when the handler for on_tick is run the next time (immediately after the second time on_entity_damaged was run), tank.speed is 0.
You can see the problem in the following screenshot: The pair of boxes (yellow: front, red: back) fits exactly around the tank's collision_box, which indicates that the tank hasn't moved backwards one bit. The smaller boxes with the gap between them indicate where the car was standing at the moment of impact. It has been pushed out of the picture by the impact from the tank. I've also tried it the other way around: Got into the car (which is not controlled by my mod), and crashed frontally into the tank. This time, the tank was bouncing a bit (because it's much heavier than the car, the impact has only a weak effect) but the car came to a full stop. However, the log did show that both bouncing speeds didn't change until the end of the second on_entity_damaged.
There really isn't any other mod running except for the Lua API global Variable Viewer (gvv), so this must be either an issue of my mod or something coming from the base game. Given that in both cases event.cause of on_entity_damaged was stopped in its tracks while event.entity did bounce, I'm inclined to say that there may be some mechanics in vanilla which I don't understand.
I've attached the relevant portion of the log file (the on_tick immediately before the crash, both on_entity_damaged events, and the beginning of on_tick following the crash). There are multiple places where I've logged the speed of tank and car, just to find out whether something in my code would set the speed of the tank (or rather: the event.cause of on_entity_damaged) to 0, but it is at the original bouncing speed all the time.
I'd be extremely glad if somebody could shed some light on this!
