Matterjs : Applyforce not the same effect on update and on a button/zone?

#1

hi,

In my update function this works perfectly : i press the left key and my player move with this cool effect :

		if (o.cursors.left.isDown) {
			o.player.applyForceFrom(
				{ x: o.player.x, y: o.player.y },
				{ x:-0.05, y:0 },
			)
		}

but when i put the same code on a zone i have not the same effect. i must press succesively on the zone to move my player and it’s not the same effect … (however its a pointerover zone ?)

b[0].left_zone = g.add.zone(0, data.h2, w3, data.h2).setOrigin(0).setInteractive()
b[0].left_zone.on('pointerover', () => {
	o.player.applyForceFrom(
		{ x: o.player.x, y: o.player.y },
		{ x:-0.05, y:0 },
	)
})

how do i do to have the same effect in my zone ?

#2

pointerover is triggered one time, when the pointer moves in to the zone.
pointerout is triggered one time, wenn the pointer leaves the zone.

So you can set a boolean flag when over is triggered and then set it to false when out is triggered.
With this flag you can then do the applyForceFrom every update in the update function.

1 Like
#3

thanks for you support