Original Post
I'm moving my game from fixed 1ms update to full delta time use and I'm having problems with collision detection now.
If my computer lags for a moment, my character goes trough a ground (ground / objects / walls) .
I tried to find good solution for fixed timestep etc. but I found it too complicated. What would be the best solution for me?
My game is 2D platformer with simple tile based collision detection.
I'm updating everything with dt like (speed = speed + acc * dt)
This is a code snippet for checking "X" collision.
Thanks for answers!
If my computer lags for a moment, my character goes trough a ground (ground / objects / walls) .
I tried to find good solution for fixed timestep etc. but I found it too complicated. What would be the best solution for me?
My game is 2D platformer with simple tile based collision detection.
I'm updating everything with dt like (speed = speed + acc * dt)
This is a code snippet for checking "X" collision.
void CPlayer::_checkCollisionX(float dt)
{
bool update = true;
int xStart, xEnd, yStart, yEnd;
xStart = (int)(getX() - (PLAYER_WIDTH / 2) - max_walk_speed*dt) / 32;
xEnd = (int)(getX() + (PLAYER_WIDTH / 2) + max_walk_speed*dt) / 32;
yStart = (int)(getY() - (PLAYER_HEIGHT / 2)) / 32;
yEnd = (int)(getY() + (PLAYER_HEIGHT / 2) - 1) / 32;
for (int i = yStart; i<= yEnd; i++)
{
if(getSpeedX() > 0)
{
if(world.map.Attributes[xEnd] == 1)
{
setX((xEnd * TILE_WIDTH) - (PLAYER_WIDTH / 2));
update = false;
setSpeedX(0.0f);
_frame = 0;
break;
}
}
else if(getSpeedX() < 0)
{
if(world.map.Attributes[xStart] == 1)
{
setX(((xStart+1) * TILE_WIDTH) + (PLAYER_WIDTH / 2));
update = false;
setSpeedX(0.0f);
_frame = 0;
break;
}
}
}
if (update)
{
setX(getX() + getSpeedX() * dt);
}
}Thanks for answers!