Jump to content

Jittery collisions with scaled sprites using arcade physics


Aniki
 Share

Recommended Posts

If my sprite's scale is set to 1, there is no jitter in the collisions. I need to scale everything in the game to x2 scale.

My player moves by setting body.velocity.x to 200 as long as I am pressing the right arrow key. When this collides with an immovable body the player jitters back and forth 1 pixel every frame.

 

I would expect this to be a very common problem, but I can't seem to find anyone talking about it anywhere. However, I did find an old topic on this issue with a solution that did not work for me: 

 

Link to comment
Share on other sites

21 hours ago, Aniki said:

My player moves by setting body.velocity.x to 200 as long as I am pressing the right arrow key. When this collides with an immovable body the player jitters back and forth 1 pixel every frame.

It jitters while you're holding the right arrow key?

Link to comment
Share on other sites

Yeah. I think the problem boils down to, if a sprite is given velocity while exactly next to an immovable body, it will move one pixel inside of the body and then get pushed back out on the next frame. So if you hold the direction key the character will continuously move back and forth in and out of the wall and will look very blurry/jittery.

It seems to be a problem with the scaling because this doesn't happen if everything stays at x1 scale.

Link to comment
Share on other sites

2 hours ago, Aniki said:

Yeah. I think the problem boils down to, if a sprite is given velocity while exactly next to an immovable body, it will move one pixel inside of the body and then get pushed back out on the next frame. So if you hold the direction key the character will continuously move back and forth in and out of the wall and will look very blurry/jittery.

That was my guess. I don't think it's hard to fix. Try either:

  1. Check collisions after you set velocity (from keyboard input); or
  2. When you set velocity, check body.touching and don't allow movement against the touching edge
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...