Please consider this scene. Developed using PhaserJS 3.
I want to make the slider move left when the player touches the right hand side of it, and move right when the player touches the left hand side of it.
This is the code I'm currently using in the collision callback to decide what to do:
hitSlider: function (player, slider) {
// ...
if (player.body.touching.left) {
slider_actions.moveSliderLeft(slider)
} else if (player.body.touching.right) {
slider_actions.moveSliderRight(slider);
}
// ...
}
This works in most cases, EXCEPT that it doesn't check if the player is touching the slider on the left, just that they're touching something on the left.
My screenshot contains an example. If the player stands on top of the slider, and walks left, they are both colliding with the sider and touching something on the left. So the slider moves left.
How can I detect the direction of the collision event itself instead?
