I did check out your ejs code.
There are several strange code
1. Why the drawingPanel was assigned to be autoscale?
2. Why maxX= -carSize/2 ???
3. Why Lmax was not defined?
You should have assigned initlal value for defined variables.
I do not know how to change your code because I do not know the specification for your simulation.
The code in the event are strange,too!
If I have something bounced between xmin and xmax (xmax>xmin)
I will have code like this for zero condition:
if (v>0)return x-xmax; // bounced at x=xmax
else if(v<0)return x-xmin; // bounced at x=xmin
// the event occurs when return value is less than zero.
And the action will be