Home Game Development Cocos Creator – Box2D Polygon Shape difficulty – Cocos Creator

Cocos Creator – Box2D Polygon Shape difficulty – Cocos Creator

0
Cocos Creator – Box2D Polygon Shape difficulty – Cocos Creator

[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&leap 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 vary the polygon collider form to match the hills. Unfortunately it occurs very often that the polygon collider form (Box2D) attracts unusual traces, that shouldn’t be there. Here is a screenshot of my present mission.

The pink line is the vertices array drawn with Lines on a Graphics object and the inexperienced space is similar vertices array (Just with some extra 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 any concept why that is occurring?
The replace code of the collider is as follows:

  replaceCollider(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!

Hi, I don’t have a solution however simply need to share my expertise doing the identical procedural logic (graphic + collider factors) and having a whole lot of invisible (not deterministic) gaps the place the participant might fall. Sadly the one resolution was to maneuver away from programmatic strategy and use simply a picture. Your recreation seems to be good, hope you discover a manner to do that :ok_man: and share it with us

Thank you in your insights :slightly_smiling_face: This is unquestionably an strategy I can take into consideration, however I positively wouldn’t choose it. Furthermore I would love to grasp why my strategy just isn’t working, as I’m fairly new to Cocos and attempt to consider it, if it truly is a match or I’d have to look into different recreation engines. Currently the Polygon Collider behaviour looks like a bug.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here