I'm trying to create a simulation in which a ball follows a motion path, similar to this:
https://bl.ocks.org/mbostock/1705868
However, instead of using tweening, I would like the ball's motion to be determined by gravity and the object's velocity - similar to a rollercoaster, like this:
https://www.myphysicslab.com/roller/roller-single-en.html
This is what I have so far, but there's a small problem in that the roller coaster is slightly gaining energy, instead of losing it, each frame:
https://jsbin.com/jidazom/edit?html,js,output
x
Any suggestions on how to fix this would be greatly appreciated!