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

Get help using Construct 2

Post » Mon Jul 24, 2017 11:47 am

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. :ugeek:
B
6
S
3
Posts: 121
Reputation: 1,630

Post » Tue Jul 25, 2017 6:31 pm

Any help would be lovely
B
6
S
3
Posts: 121
Reputation: 1,630

Post » Tue Jul 25, 2017 9:21 pm

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.
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267


Return to How do I....?

Who is online

Users browsing this forum: 25games, Yahoo [Bot] and 7 guests