wiserim / phaser-raycaster

Raycasting plugin for Phaser 3. Documentation:

Home Page:https://wiserim.github.io/phaser-raycaster/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An exception when calling mapGameObjects with some concave bodies in 0.10.7/8

dreasgrech opened this issue · comments

In my game I am using shapes from PhysicsEditor to generate Matter Sprites with polygon shapes for Matter colliders. These sprites are then passed into raycaster.mapGameObjects as dynamic.

But since I upgraded to 0.10.7/8, I started getting an exception thrown when calling mapGameObjects with certain, but not all, concave shapes.

I suspect it might have to do with the recent optimization that was introduced in 0.10.7 regarding the array of neighbours. For this specific error to be thrown, it seems like the pointA.neighbours array is missing for some reason.

image

image

The sprite is created as follows:

const hullImage = gameContext.matter.add.sprite(
    x,
    y,
    ImageDatabase.GameElementsSpritesheetKey,
    hullPhaserImageKey,
    {
        shape: shapes[hullPhysicsShapeName],
    }
);

This is an example of shapes[hullPhysicsShapeName] which throws the exception:

{"type":"fromPhysicsEditor","label":"AngelicaBot_Hull","isStatic":false,"density":0.10000000149011612,"restitution":0,"friction":0.10000000149011612,"frictionAir":0.01,"frictionStatic":0.5,"collisionFilter":{"group":0,"category":1,"mask":255},"fixtures":[{"label":"","isSensor":false,"vertices":[[{"x":0,"y":19},{"x":12,"y":6},{"x":47,"y":2},{"x":90,"y":14},{"x":215,"y":64},{"x":5,"y":42}],[{"x":1,"y":124},{"x":0,"y":102},{"x":91,"y":127},{"x":71,"y":139},{"x":13,"y":137}],[{"x":47,"y":2},{"x":71,"y":2},{"x":90,"y":14}],[{"x":0,"y":102},{"x":5,"y":97},{"x":214,"y":76},{"x":229,"y":98},{"x":231,"y":125},{"x":91,"y":127}],[{"x":90,"y":14},{"x":228,"y":14},{"x":233,"y":19},{"x":233,"y":35},{"x":215,"y":64}],[{"x":0,"y":59},{"x":5,"y":42},{"x":215,"y":64},{"x":214,"y":76},{"x":5,"y":97}]]}]}

And this is an example of shapes[hullPhysicsShapeName] which DOES NOT throw the exception:

{"type":"fromPhysicsEditor","label":"Hull_01","isStatic":false,"density":0.1,"restitution":0,"friction":0.1,"frictionAir":0.02,"frictionStatic":0.5,"collisionFilter":{"group":0,"category":1,"mask":255},"fixtures":[{"label":"","isSensor":false,"vertices":[[{"x":182,"y":47},{"x":240,"y":46},{"x":250,"y":57},{"x":251,"y":91},{"x":228,"y":102}],[{"x":228,"y":154},{"x":240,"y":154},{"x":250,"y":165},{"x":251,"y":199},{"x":244,"y":206},{"x":182,"y":210},{"x":171,"y":194}],[{"x":3,"y":57},{"x":14,"y":47},{"x":72,"y":46},{"x":171,"y":194},{"x":12,"y":99},{"x":5,"y":92}],[{"x":171,"y":62},{"x":182,"y":47},{"x":228,"y":102},{"x":228,"y":154},{"x":171,"y":194}],[{"x":3,"y":113},{"x":12,"y":99},{"x":12,"y":148},{"x":4,"y":143}],[{"x":3,"y":165},{"x":12,"y":148},{"x":83,"y":194},{"x":72,"y":209},{"x":14,"y":210},{"x":4,"y":199}],[{"x":12,"y":148},{"x":12,"y":99},{"x":171,"y":194},{"x":83,"y":194}],[{"x":83,"y":62},{"x":171,"y":62},{"x":171,"y":194}]]}]}

Thank you reporting these issues.
The problem lies in my assumption, that mapped matter objects will have closed shapes.
In your examples shapes are not closed which couse problems.
I'll rework mapping for matter objects.

Version 0.10.9 has been released.
Pull request: #47

I've reworked mapping for matter objects.
Now it maps concave objects properly.

Cheers, just tried v0.10.9 now and can confirm that it's fixed.