Collisions

#1

Hello.

I am currently building a game in which my main sprite is no other than… captain america! :smile:
To make him swing the enemies and walk to reck thanos(does he really?) I used a sprite sheet. So far so good, however now I want him to actually hit enemies. I was wondering how I can manage to detect the collision exactly. I can detect the bounding boxes collision with arcade physics, however I wanted to detect only when his fist hits the enemy. With pure JS I used a function to detect this pixel perfect collision, using the alpha value of each pixel. I was wondering if there was any way to do that in phaser.

30
(not colliding)

08
(colliding)

Thank you for your time!!

0 Likes

#2

Usually, in game of this type, you must create a new hitbox (or a new Phaser Sprite) when the player execute a attack.

1 Like

#3

How can I perform that?

0 Likes

#4

Looks pretty cool. Have you looked at Physics Editor (https://www.codeandweb.com/physicseditor) I think that along with matter.js can be what you need. There’s a cool example at: https://labs.phaser.io/view.html?src=src\physics\matterjs\advanced%20shape%20creation.js

I haven’t tried it yet, but might help you.

Take care,
DaSoup

0 Likes

#5

Hello man. Thank you for your answer.

I actually have tried it out. It’s a nice feature, however I found myself having to change body physics all the time. I managed to do that(despite the lack of documentation and information about that), by using the setBody() function, passing as parameter the physics texture, the x and y(yea, you have to specify it too). This worked fine for texture changing, however not so great for my sprite position and gravity. Because it’s constantly modifying the x and y, the physics don’t have time to ‘act’ properly, so when I jumped with my sprite it looked a bit awkward. Moving left and right seemed to work just fine.

After that I found that I needed to also rotate my sprite body physics, because my sprite sheet only has one direction of the sprite, and when I want to rotate it on animation I just do a .setFlipX(true) and works like a charm. I was hoping there was a function like that for physics, but no, nothing. So I had to add body physics on every moving direction. More trouble… There’s when I decided to stop trying because I have a deadline for this project and if I keep messing around with this I think I will always have a stone in my shoe.

What I hope phaser creators do is to document and give more examples about this framework, because I felt like it wasn’t yet at the level of Arcade Physics and it has much more potencial.

Oh and also I hope that someone starts an opensource project like Physics Editor, because it is payed ^^

Any ideas, thoughts about this problem and experiencies with this framework are welcome to the discussion! Cheers

0 Likes