
[ad_1]
Hey,
I’m at the moment engaged on a Game with a Tiny Wings/Dune like mechanic. Therefore I’m procedurally creating hills, that the participant is ready to dive&soar on. Currently 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. Unfortunately it occurs very often that the polygon collider form (Box2D) attracts unusual strains, that shouldn’t be there. Here is a screenshot of my present undertaking.
The pink line is the vertices array drawn with Lines on a Graphics object and the inexperienced space is identical vertices array (Just with some further begin and endpoints to shut the form), drawn by the debug command:
PhysicsSystem2D.occasion.debugDrawFlags = EPhysics2DDrawFlags.Shape;
Currently there are roughly 180 vertices within the array. Do you’ve got any thought 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 on your help upfront!
[ad_2]