Way to round the x and y position values of physics objects?

I have a game with lots of characters and want to use a retro pixel style. Everything looks fine and based on a screen size of 320x480px the map on the screen and the characters are looking good in pixel block style. But when I’m using physics on the characters they move not in “steps” of the pixel size, but in real screen pixels, so it can happen their pixels can be “off” compared to the map pixels in the background or compared to each others pixel positions.

I now wonder if there is a way to move physics objects in integer steps and not float values or some other way to avoid wrong positions of the characters?

Hi Daniela,

It’s valid to move physics objects by merely setting/shifting the x/y position, and you should still get collision events (well, technically, you’d get the collision event on the next time-step after moving the object, but that’s how normal collisions work too). So, if you don’t want to use the physics-based methods to apply force and velocity, just move the objects around directly.

Best regards,

Brent

Exactly, plus limitation to no change during collision (because it will disrupt collision computations). Use preCollision, postCollision or performWithDelay to change x, y for phycics bodies to avoid such changes during collisions.

Hi Daniela,

It’s valid to move physics objects by merely setting/shifting the x/y position, and you should still get collision events (well, technically, you’d get the collision event on the next time-step after moving the object, but that’s how normal collisions work too). So, if you don’t want to use the physics-based methods to apply force and velocity, just move the objects around directly.

Best regards,

Brent

Exactly, plus limitation to no change during collision (because it will disrupt collision computations). Use preCollision, postCollision or performWithDelay to change x, y for phycics bodies to avoid such changes during collisions.