1
votes

I'm making a game which basically is to move a truck with furniture to the destination. I'm using Phaser with P2 engine.

I'm now facing problem with putting the furniture inside the truck. I've tried:
1. Making the truck parent and furniture child(Using addChild()). However, after enabling gravity the furniture just fell without any collision.
2. Setting a rectangle bound, but it collides with the truck.
3. Using PhysicsEditor to hollow out the truck sprite, but it doesn't seem to let me do that.
Now I'm down with one last method which is separate the roof and let the truck become two sprites, but I'm hoping for a better way to do this.

There is another post with the same problem but no answer(Phaser P2 Physics Hollow sprite) so I think I'd try asking again.
Thank you!

2

2 Answers

1
votes

Try to make the truck with 2 sprites one for the "backrground" and one for the "edges" when you move the truck you move both sprites at the same time. Then you make your colision between the furnitures and the edges of the truck.

I did something like that a while ago with the ARCADE engine and it worked fine.

0
votes

My friend and I found a bypass without any coding. We cut a 1px hole in the truck and used PhysicsEditor to "hollow" out the truck. Since it's only 1px we think not many people will notice it. Still, it is only a temporary solution.

Below is a graph for demonstration:
enter image description here