Aniki Posted September 26, 2017 Share Posted September 26, 2017 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 More sharing options...
samme Posted September 26, 2017 Share Posted September 26, 2017 Are you scaling the sprite or the world/camera? Link to comment Share on other sites More sharing options...
Aniki Posted September 26, 2017 Author Share Posted September 26, 2017 Right now I am scaling the sprite via group.setScale(2,2). Previously I was using world scale Link to comment Share on other sites More sharing options...
samme Posted September 26, 2017 Share Posted September 26, 2017 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 More sharing options...
Aniki Posted September 26, 2017 Author Share Posted September 26, 2017 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 More sharing options...
Aniki Posted September 26, 2017 Author Share Posted September 26, 2017 I'm actually just going to make my own collision engine using projection. I'm getting too caught up in trying to use the built-in system. Link to comment Share on other sites More sharing options...
samme Posted September 27, 2017 Share Posted September 27, 2017 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: Check collisions after you set velocity (from keyboard input); or When you set velocity, check body.touching and don't allow movement against the touching edge Link to comment Share on other sites More sharing options...
Recommended Posts