0XDE57 / SpaceProject

An arcadey physics based top-down 2D, procedurally generated asteroid miner sandbox game using libGDX.
Apache License 2.0
38 stars 10 forks source link

broken origin: item drop not centered #30

Open 0XDE57 opened 1 year ago

0XDE57 commented 1 year ago

item drops for asteroids are not centered, they spawn off center.

problem was wrong origin for box2d body vs point (highlighted green is correct center origin, highlighted purple is incorrect off-center origin) Image

the fix was to shift the points that define the hull by the polygon centroid:

//shift vertices to be centered around 0,0 relatively
Vector2 center = new Vector2();
GeometryUtils.polygonCentroid(hull, 0, hull.length, center);
for (int j = 0; j < hull.length; j += 2) {
    hull[j] -= center.x;
    hull[j + 1] -= center.y;
}

this fixes the issue:

Image

but this now causes issue #2 to happen in every case

0XDE57 commented 3 weeks ago

NOTE: the child polygon origin is still incorrect!

only the drops spawn location is now correct relative to the polygon.