Hello there,
I created some object boxes in Tiled, I created my player and then I created my enemies like this:
objectsLayer.objects.forEach(objData => {
const { x = 0, y = 0, name, width = 0, height = 0 } = objData; switch (name) { case 'player-spawn': { //adição do player (frame 0, imagem 0 na sprite) this.player = this.matter.add.sprite(x + (width * 0.5), y, 'player', 0); this.player.body.label = 'player'; this.player.setCollisionGroup(2); this.player.setFixedRotation(); this.player.setFriction(0);
…
case 'golem1_1': {
>
> this.golem1_1 = this.matter.add.sprite(x + (width * 0.5), y, 'golem1', 0);
> this.golem1_1.setBody({
> type: 'rectangle',
> width: 130,
> height: 200,
> });
>
> this.golem1_1.setFixedRotation();
> this.golem1_1.setScale(.15);
>
> } break;
I have more enemies, but I created them individually.
Movement:
I want to make them move from one side to another and when they collide with a wall I want them to turn the other way, but I don’t know how to do it and haven’t found the solution.
Kill enemy:
I would like to make the player kill the enemy jumping on top of it, but I don’t know how to do it using matter.
Enemy attack:
I would also like to make the enemy attack the player when the player collides with the enemy, on the sides.
I could make the enemy collide with the player using something like this, but it wouldn’t work the way I want:
this.matter.world.on(“collisionstart”, (e, o1, o2) => {
if ([o1.label, o2.label].indexOf('golem1_1') != -1 && [o1.label, o2.label].indexOf('player') != -1) { this.playerhp--; } });
I believe the collision should be on create, so how would I make the enemy attack animation trigger on collision?
One more thing, when I hit the golem with the player, the golem falls even with fixedRotation, I don’t know why.
I need help as soon as possible, If you can.
Thanks