Aborting due to Chipmunk error: Polygon is concave or has a reversed winding. Consider using cpConvexHull() or CP_CONVEX_HULL().
Failed condition: cpPolyValidate(verts, numVerts)
I do know the correct direction counter clock or inverse, but i tried the two directions, and get the same error on both.
Answer is in error text: “Consider using cpConvexHull() or CP_CONVEX_HULL()”
What you are trying to do is create concave polygon which leads to error. You need to decompose object to convex polygons or create convex hull with cpConvexHull().
I solved it with inverse y value. I draw object in TileMap from bottom-left position.
If you won’t inverse, you can try draw object from top-right position.
long count = platformVertex.size();
Vec2 vertex[count];
Vec2 prev = Vec2::ZERO;
int i =0 ;
for( Value pointVal : platformVertex)
{
ValueMap point = pointVal.asValueMap();
CCLOG("pol x = %f y = %f", point["x"].asFloat(), point["y"].asFloat());
prev = startPoint + Vec2(point["x"].asFloat(), point["y"].asFloat() * -1);
vertex[i] = prev;
i++;
}
ValueMap lastPoint = platformVertex[0].asValueMap();
vertex[count-1] = startPoint + Vec2(lastPoint["x"].asFloat(), lastPoint["y"].asFloat() * -1);
Vec2 off= Vec2::ZERO;
PhysicsBody* body = PhysicsBody::createPolygon(vertex, count, PhysicsMaterial(1.0, 0.0f, 1.0f), off);