How do I ignore 1 pixel vibration (back and forth)?

From the Asset Store
Per Pixel Destruction like in "Worms" (perfect performance, no third party plugins)
  • In my project, there is an (invisible) physics body which does the movement etc.

    Textures on top of it are pinned to it through

    #Every tick ---> set X to floor(phybody.X)#

    *floor() is used because I use point sampling, thus I need the visible bodies to be on int pixels

    The problem here is that the Physics body does it's fair share of vibrating 0.5 pixels back and forth, thus causing vibrations on the visible texture. Is there a simple algorithm to make it ignore 0.5-1 pixel movement back and forth, and only move 2+ pixels? Math isn't my greatest strenght, so please help.

    Thanks in advance.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Any help would be lovely

  • I guess you could do some smoothing of the position with previous one's. just save the previous physics position to a variable. Sampling older positions for more smoothing may not be too useful.

    every tick

    --- sprite: set x to int((phybody.x+self.oldx)/2)

    --- sprite: set oldx to phybody.x

    I guess you could also only move if the physics object moves 2 pixels or more. I think that may just make it look like things are getting stuck.

    pick by comparison: sprite: abs(int(pysbody.x)-sprite.oldx) >=2

    --- sprite: set x to int(physbody.x)

    every tick

    --- sprite: set oldx to phybody.x

    You may also try round() instead of rounding down with int() or floor(). Not sure that would matter in the slightest though.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)