Skip to main content
Added more detail
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Edit

As I mentioned above, I have tried making a copy of the sprite's coordinates specifically to draw with.... this has it's own problems.

Firstly, regardless of the copying, when the sprite is moving, it's super-smooth, when it stops, it's wobbling slightly left/right - as it's still extrapolating it's position based on the time. Is this normal behavior and can we 'turn it off' when the sprite stops?

I've tried having flags for left / right and only extrapolating if either of these is enabled. I've also tried copying the last and current positions to see if there is any difference. However, as far as collision goes, these don't help.

If the user is pressing say, the right button and the sprite is moving right, when it hits a wall, if the user continues to hold the right button down, the sprite will keep animating to the right, while being stopped by the wall (therefore not actually moving), however because the right flag is still set and also because the collision routine is constantly moving the sprite out of the wall, it still appear to the code (not the player) that the sprite is still moving, and therefore extrapolation continues. So what the player would see, is the sprite 'static' (yes, it's animating, but it's not actually moving across the screen), and every now and then it shakes violently as the extrapolation attempts to do it's thing....... Hope this help

Edit

As I mentioned above, I have tried making a copy of the sprite's coordinates specifically to draw with.... this has it's own problems.

Firstly, regardless of the copying, when the sprite is moving, it's super-smooth, when it stops, it's wobbling slightly left/right - as it's still extrapolating it's position based on the time. Is this normal behavior and can we 'turn it off' when the sprite stops?

I've tried having flags for left / right and only extrapolating if either of these is enabled. I've also tried copying the last and current positions to see if there is any difference. However, as far as collision goes, these don't help.

If the user is pressing say, the right button and the sprite is moving right, when it hits a wall, if the user continues to hold the right button down, the sprite will keep animating to the right, while being stopped by the wall (therefore not actually moving), however because the right flag is still set and also because the collision routine is constantly moving the sprite out of the wall, it still appear to the code (not the player) that the sprite is still moving, and therefore extrapolation continues. So what the player would see, is the sprite 'static' (yes, it's animating, but it's not actually moving across the screen), and every now and then it shakes violently as the extrapolation attempts to do it's thing....... Hope this help

It was pointed out that I was extrapolating, not interpolating, so have ammended the question to reflect this
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Interpolation Extrapolation breaks collision detection

Before applying interpolationextrapolation to my sprite's movement, my collision worked perfectly. However, after applying interpolationextrapolation to my sprite's movement (to smooth things out), the collision no longer works.

This is how things worked before interpolationextrapolation:

enter image description here

However, after I implement my interpolationextrapolation, the collision routine breaks. I am assuming this is because it is acting upon the new coondinatecoordinate that has been produced by the interpolationextrapolation routine (which is situated in my render call ).

After I apply my interpolationextrapolation

enter image description here

How to correct this behaviour?

I've tried puting an extra collision check just after interpolationextrapolation - this does seem to clear up a lot of the problems but I've ruled this out because putting logic into my rendering is out of the question.

I've also tried making a copy of the spritesX position, interpolatingextrapolating that and drawing using that rather than the original, thus leaving the original intact for the logic to pick up on - this seems a better option, but it still produces some weird effects when colliding with walls. I'm pretty sure this also isn't the correct way to deal with this.

I've found a couple of similar questions on here but the answers haven't helped me.

This is my interpolationextrapolation code:

public void onDrawFrame(GL10 gl) {
    
    
        //Set/Re-set loop back to 0 to start counting again
        loops=0;
    
        while(System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){
    
        SceneManager.getInstance().getCurrentScene().updateLogic();
        nextGameTick+=skipTicks;
        timeCorrection += (1000d/ticksPerSecond) % 1;
        nextGameTick+=timeCorrection;
        timeCorrection %=1;
        loops++;
        tics++;

     }

        interpolationextrapolation = (float)(System.currentTimeMillis() + skipTicks - nextGameTick) / (float)skipTicks; 
            
        render(interpolationextrapolation);
}

Applying interpolationextrapolation

            render(float interpolationextrapolation){

            //This example shows interpolationextrapolation for X axis only.  Y position (spriteScreenY is assumed to be valid)
            interpolatedPosXextrapolatedPosX = spriteGridX+(SpriteXVelocity*dt)*interpolation;*extrapolation;
            spriteScreenPosX = interpolationPosXextrapolationPosX * screenWidth;

            drawSprite(spriteScreenX, spriteScreenY);           


        }

Interpolation breaks collision detection

Before applying interpolation to my sprite's movement, my collision worked perfectly. However, after applying interpolation to my sprite's movement (to smooth things out), the collision no longer works.

This is how things worked before interpolation:

enter image description here

However, after I implement my interpolation, the collision routine breaks. I am assuming this is because it is acting upon the new coondinate that has been produced by the interpolation routine (which is situated in my render call ).

After I apply my interpolation

enter image description here

How to correct this behaviour?

I've tried puting an extra collision check just after interpolation - this does seem to clear up a lot of the problems but I've ruled this out because putting logic into my rendering is out of the question.

I've also tried making a copy of the spritesX position, interpolating that and drawing using that rather than the original, thus leaving the original intact for the logic to pick up on - this seems a better option, but it still produces some weird effects when colliding with walls. I'm pretty sure this also isn't the correct way to deal with this.

I've found a couple of similar questions on here but the answers haven't helped me.

This is my interpolation code:

public void onDrawFrame(GL10 gl) {
    
    
        //Set/Re-set loop back to 0 to start counting again
        loops=0;
    
        while(System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){
    
        SceneManager.getInstance().getCurrentScene().updateLogic();
        nextGameTick+=skipTicks;
        timeCorrection += (1000d/ticksPerSecond) % 1;
        nextGameTick+=timeCorrection;
        timeCorrection %=1;
        loops++;
        tics++;

     }

        interpolation = (float)(System.currentTimeMillis() + skipTicks - nextGameTick) / (float)skipTicks; 
            
        render(interpolation);
}

Applying interpolation

            render(float interpolation){

            //This example shows interpolation for X axis only.  Y position (spriteScreenY is assumed to be valid)
            interpolatedPosX = spriteGridX+(SpriteXVelocity*dt)*interpolation;
            spriteScreenPosX = interpolationPosX * screenWidth;

            drawSprite(spriteScreenX, spriteScreenY);           


        }

Extrapolation breaks collision detection

Before applying extrapolation to my sprite's movement, my collision worked perfectly. However, after applying extrapolation to my sprite's movement (to smooth things out), the collision no longer works.

This is how things worked before extrapolation:

enter image description here

However, after I implement my extrapolation, the collision routine breaks. I am assuming this is because it is acting upon the new coordinate that has been produced by the extrapolation routine (which is situated in my render call ).

After I apply my extrapolation

enter image description here

How to correct this behaviour?

I've tried puting an extra collision check just after extrapolation - this does seem to clear up a lot of the problems but I've ruled this out because putting logic into my rendering is out of the question.

I've also tried making a copy of the spritesX position, extrapolating that and drawing using that rather than the original, thus leaving the original intact for the logic to pick up on - this seems a better option, but it still produces some weird effects when colliding with walls. I'm pretty sure this also isn't the correct way to deal with this.

I've found a couple of similar questions on here but the answers haven't helped me.

This is my extrapolation code:

public void onDrawFrame(GL10 gl) {
    
    
        //Set/Re-set loop back to 0 to start counting again
        loops=0;
    
        while(System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){
    
        SceneManager.getInstance().getCurrentScene().updateLogic();
        nextGameTick+=skipTicks;
        timeCorrection += (1000d/ticksPerSecond) % 1;
        nextGameTick+=timeCorrection;
        timeCorrection %=1;
        loops++;
        tics++;

     }

        extrapolation = (float)(System.currentTimeMillis() + skipTicks - nextGameTick) / (float)skipTicks; 
            
        render(extrapolation);
}

Applying extrapolation

            render(float extrapolation){

            //This example shows extrapolation for X axis only.  Y position (spriteScreenY is assumed to be valid)
            extrapolatedPosX = spriteGridX+(SpriteXVelocity*dt)*extrapolation;
            spriteScreenPosX = extrapolationPosX * screenWidth;

            drawSprite(spriteScreenX, spriteScreenY);           


        }
Tweeted twitter.com/#!/StackGameDev/status/469150213332942848
Source Link
BungleBonce
  • 1.9k
  • 2
  • 34
  • 69

Interpolation breaks collision detection

Before applying interpolation to my sprite's movement, my collision worked perfectly. However, after applying interpolation to my sprite's movement (to smooth things out), the collision no longer works.

This is how things worked before interpolation:

enter image description here

However, after I implement my interpolation, the collision routine breaks. I am assuming this is because it is acting upon the new coondinate that has been produced by the interpolation routine (which is situated in my render call ).

After I apply my interpolation

enter image description here

How to correct this behaviour?

I've tried puting an extra collision check just after interpolation - this does seem to clear up a lot of the problems but I've ruled this out because putting logic into my rendering is out of the question.

I've also tried making a copy of the spritesX position, interpolating that and drawing using that rather than the original, thus leaving the original intact for the logic to pick up on - this seems a better option, but it still produces some weird effects when colliding with walls. I'm pretty sure this also isn't the correct way to deal with this.

I've found a couple of similar questions on here but the answers haven't helped me.

This is my interpolation code:

public void onDrawFrame(GL10 gl) {
    
    
        //Set/Re-set loop back to 0 to start counting again
        loops=0;
    
        while(System.currentTimeMillis() > nextGameTick && loops < maxFrameskip){
    
        SceneManager.getInstance().getCurrentScene().updateLogic();
        nextGameTick+=skipTicks;
        timeCorrection += (1000d/ticksPerSecond) % 1;
        nextGameTick+=timeCorrection;
        timeCorrection %=1;
        loops++;
        tics++;

     }

        interpolation = (float)(System.currentTimeMillis() + skipTicks - nextGameTick) / (float)skipTicks; 
            
        render(interpolation);
}

Applying interpolation

            render(float interpolation){

            //This example shows interpolation for X axis only.  Y position (spriteScreenY is assumed to be valid)
            interpolatedPosX = spriteGridX+(SpriteXVelocity*dt)*interpolation;
            spriteScreenPosX = interpolationPosX * screenWidth;

            drawSprite(spriteScreenX, spriteScreenY);           


        }