Programming in Java. Tinkering around with physics. My entities all have position and velocity. In the main loop, all I'm doing is applying gravity and bouncing off the edges, like so:
// add gravity vector
o.velocity.add(GRAVITY.cpy().mul(dt));
// bounce off walls
if ((o.position.x<0 && o.velocity.x<0) || (o.position.x>WORLD_SIZE_X && o.velocity.x>0))
o.velocity.x*=-1;
// bounce off of ground
if (o.position.y<=0.0f) {
o.position.y=0.0f;
if (o.velocity.y<0)
o.velocity.y *= -1;
}
The x and y values of my vectors are just floats.
For the first second it looks like it's working fine, but the vertical velocities slowly decay. Any idea why?
z.velocity += Gravity * dt;
, for Java code.) \$\endgroup\$