Tuesday, November 8, 2022
HomeGame DevelopmentCocos Creator - Box2D Polygon Form subject - Cocos Creator

Cocos Creator – Box2D Polygon Form subject – Cocos Creator


Hey,

I’m presently engaged on a Recreation with a Tiny Wings/Dune like mechanic. Subsequently I’m procedurally creating hills, that the participant is ready to dive&bounce on. At the moment 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 vary the polygon collider form to match the hills. Sadly it occurs very often that the polygon collider form (Box2D) attracts unusual traces, 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 extra begin and endpoints to shut the form), drawn by the debug command:

PhysicsSystem2D.occasion.debugDrawFlags = EPhysics2DDrawFlags.Form;

At the moment there are roughly 180 vertices within the array. Do you could have any thought why that is occurring?
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 in your help upfront!


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments