Regarding the frame rate problem: I didn't go through your code in detail but one thing you have to make sure is that you're using time and calculating other physical quantities correctly. Here's an example for a while loop:
Force = ...
Acceleration = Force / Mass
Velocity += Acceleration * DeltaTime
Position += Velocity * DeltaTime
In your case you can leave out the acceleration part and modify the velocity manually.
Edit: so I took a look at your code and it seems to follow the basic principle, I guess the problem is somewhere else.
Also what do you mean by "goes wrong"?
Last edited by Kartoffel; 04/18/18 06:20.