In a platformer game I'm making I'm going to use Verlet Integration, so in the player calculate function. At the moment I have it set up like this:
//// Velocity Verlet integration
lastAcceleration = avgAcceleration;
nextPosition.x += velocity.x * delta + ( 0.5 * lastAcceleration.x * delta * delta);
nextPosition.y += velocity.y * delta + ( 0.5 * lastAcceleration.y * delta * delta);
// Collision Detection - I wont put this in the sample code
// Move to new coords
position = nextPosition;
// Initialise Acceleration
newAcceleration.x = 0.0;
newAcceleration.y = 0.0;
// Gravity
if (!yCollision)
{
double force = mass * -0.0001;
newAcceleration.y = force * delta / mass;
}
// Air Resistance
velocity.x -= velocity.x * 0.01 * delta;
// Controls
if (key['W'] && yCollision)
{
double force = mass * 0.05;
newAcceleration.y = force / mass;
}
if (key['A'])
{
double force = mass * -0.003;
newAcceleration.x += force / mass;
facingLeft = true;
}
if (key['D'])
{
double force = mass * 0.003;
newAcceleration.x += force / mass;
facingLeft = false;
}
avgAcceleration.x = (lastAcceleration.x + newAcceleration.x) / 2.0;
avgAcceleration.y = (lastAcceleration.y + newAcceleration.y) / 2.0;
velocity.x += avgAcceleration.x * delta;
velocity.y += avgAcceleration.y * delta;
//// Velocity Verlet integration
However, The jumping still seems to be majorly affected by the frame rate. Have I set up the integration properly?