1
General / Jittering in Player Sprite and Camera Movement
« on: October 10, 2021, 02:43:10 am »
Hi, I'm starting a little game and I'm having some basic problems with jittering. My project is a bit long, so I simplified everything into a single main.cpp with around 250 lines of code.
https://github.com/HiperDoo/Jittering-Problem
I tryed to make the camera always follow the player and that the camera can move smoothly when the player accelerates and when brakes hard. And it works, the bad thing is that there is a very annoying little jitering (and its not solved only by placing a maximum speed, since you can see the jittering when accelerating and decelerating).
I really tried a lot of convinations with the std::floor(), std::round() and std::fmod() functions. I've been trying to solve it for 3 days.
An example (obviously you can't see the jittering in an image):
I would be REALLY GRATEFUL if someone could modify the code I made to fix this jittering pleace.
#Details:
- The TileMap and the red box (player's hitbox) are drawn on the same Render Texture and moved with the camera. The player sprite is drawn in the window using "mapCoordsToPixel" from the hitbox (for some reason a jittering occurs, even having the same coordinates).
- There are 3 factors to take into account, the movement of the camera, the hitbox of the player and the sprite of the player. There is jittering between the camera position and the hitbox, also between the hitbox and the sprite (terrible ).
- The player's sprite must continue to be drawn outside the tilemap's render texture (I want to make modifications to it without altering the tilemap, in addition to being scaled).
https://github.com/HiperDoo/Jittering-Problem
I tryed to make the camera always follow the player and that the camera can move smoothly when the player accelerates and when brakes hard. And it works, the bad thing is that there is a very annoying little jitering (and its not solved only by placing a maximum speed, since you can see the jittering when accelerating and decelerating).
I really tried a lot of convinations with the std::floor(), std::round() and std::fmod() functions. I've been trying to solve it for 3 days.
An example (obviously you can't see the jittering in an image):
I would be REALLY GRATEFUL if someone could modify the code I made to fix this jittering pleace.
#Details:
- The TileMap and the red box (player's hitbox) are drawn on the same Render Texture and moved with the camera. The player sprite is drawn in the window using "mapCoordsToPixel" from the hitbox (for some reason a jittering occurs, even having the same coordinates).
- There are 3 factors to take into account, the movement of the camera, the hitbox of the player and the sprite of the player. There is jittering between the camera position and the hitbox, also between the hitbox and the sprite (terrible ).
- The player's sprite must continue to be drawn outside the tilemap's render texture (I want to make modifications to it without altering the tilemap, in addition to being scaled).