Hey,
I’m at present engaged on a Sport with a Tiny Wings/Dune like mechanic. Subsequently I’m procedurally creating hills, that the participant is ready to dive&soar on. At present I’ve an array of vertices from which I draw the boundary of these hills on a Graphics object. I’m utilizing the identical vertices array to alter the polygon collider form to match the hills. Sadly it occurs very often that the polygon collider form (Box2D) attracts unusual strains, that shouldn’t be there. Here’s a screenshot of my present challenge.
The purple line is the vertices array drawn with Strains on a Graphics object and the inexperienced space is identical vertices array (Simply with some further begin and endpoints to shut the form), drawn by the debug command:
PhysicsSystem2D.occasion.debugDrawFlags = EPhysics2DDrawFlags.Form;
At present there are roughly 180 vertices within the array. Do you have got any concept why that is taking place?
The replace code of the collider is as follows:
updateCollider(vertices: Vec2[]) {
const collider = this.node.getComponent(PolygonCollider2D);
collider.factors = [
new Vec2(vertices[0].x, 0),
...vertices,
new Vec2(vertices[vertices.length - 1].x, 0),
new Vec2(vertices[0].x, 0),
];
collider.apply();
}
Thanks to your assist prematurely!
Hello, I don’t have a solution however simply need to share my expertise doing the identical procedural logic (graphic + collider factors) and having plenty of invisible (not deterministic) gaps the place the participant may fall. Sadly the one resolution was to maneuver away from programmatic strategy and use simply a picture. Your recreation appears good, hope you discover a method to do that and share it with us
Thanks to your insights That is positively an strategy I can take into consideration, however I positively wouldn’t desire it. Moreover I would like to grasp why my strategy shouldn’t be working, as I’m fairly new to Cocos and attempt to consider it, if it truly is a match or I’d must look into different recreation engines. At present the Polygon Collider behaviour looks as if a bug.