Muin
1
I was wondering how can I detect that the image is falling down with the matter physics
var player = this.matter.add.image(0, -500, ‘player’, null, { shape: shapePlayer.player});
because when it’s falling down, I want its angle to be 0 so it doesn’t fall upside down or something
if (player.body.touching.down==false){player.angle=0}
or
var playerFalling=null;
if (player.body.touching.down==false||player.body.touching.down!=true){playerFalling=false};
if (playerFalling==false || playerFalling!=true){player.angle=0};
Muin
3
this player.body.touching.down returns me undefined
Muin
5
var config = {
type: Phaser.AUTO,
width: 1000,
height: 600,
scene: {
preload: preload,
create: create,
update: update
},
physics: {
default: 'matter',
matter: {
gravity: {
x: 0,
y: 3
},
debug: true,
debugBodyColor: Phaser.Display.Color.GetColor(255, 255, 20)
}
},
autoFocus: true
};
var game = new Phaser.Game(config);
var platforms;
var keys;
var player;
function preload() {
this.load.image('backgroundMap', '');
this.load.json('shapeMap', '')
this.load.json('shapeCharacter', '.')
this.load.image('map', '');
this.load.image('characterPlayer', '');
}
function create() {
var shapeMap = this.cache.json.get('shapeMap');
var shapeCharacter = this.cache.json.get('shapeCharacter');
var background = this.add.image(0, 0, 'backgroundMap', null).setScale(1.35);
var map = this.matter.add.image(0, 0, 'map', null, { shape: shapeMap.fore2 });
map.setStatic(true)
player = this.matter.add.sprite(0, -500, 'characterPlayer', null, { shape: shapeCharacter.character });
keys = this.input.keyboard.addKeys('W, A, S, D, LEFT, RIGHT, UP, DOWN');
this.cameras.main.setBounds(-1010, -900, map.width, map.height);
this.cameras.main.startFollow(player);
}
function update() {
if (keys.D.isDown || keys.RIGHT.isDown) {
player.setVelocityX(3)
player.flipX = false;
}
else if (keys.A.isDown || keys.LEFT.isDown) {
player.setVelocityX(-3)
player.flipX = true;
} else {
player.setVelocityX(0);
}
if (keys.W.isDown) {
player.y -= 50;
}
If you run a console.log(player) does it have a .body? And if not, does it have .touching?
Muin
7
yes it has body but no touching
This is probably outside of best practice, but does it work if you use this.matter.add.sprite()?
Muin
9
I’m already using this line in code
My bad. I didn’t catch the change from the OP. And looking at some of my other projects, .touching is an Arcade Physics thing only.
Here is the closest workaround I could find. I hope it helps, or someone who knows more than I do has a solution.
Muin
11
Yes, I was trying to use the collision, but I needed an event that is not in the collision, but I cannot find