diff --git a/src/api/l_physics_shapes.c b/src/api/l_physics_shapes.c index d923d7fd..66e4a7ae 100644 --- a/src/api/l_physics_shapes.c +++ b/src/api/l_physics_shapes.c @@ -114,8 +114,8 @@ Shape* luax_newterrainshape(lua_State* L, int index) { uint32_t n = luax_optu32(L, index + 1, 100); float* vertices = lovrMalloc(sizeof(float) * n * n); for (uint32_t i = 0; i < n * n; i++) { - float x = scaleXZ * (-.5f + ((float) (i % n)) / n); - float z = scaleXZ * (-.5f + ((float) (i / n)) / n); + float x = scaleXZ * (-.5f + ((float) (i % n)) / (n - 1)); + float z = scaleXZ * (-.5f + ((float) (i / n)) / (n - 1)); lua_pushvalue(L, index); lua_pushnumber(L, x); lua_pushnumber(L, z); diff --git a/src/modules/physics/physics_jolt.c b/src/modules/physics/physics_jolt.c index 5ae4121d..9fb560d6 100644 --- a/src/modules/physics/physics_jolt.c +++ b/src/modules/physics/physics_jolt.c @@ -964,9 +964,9 @@ TerrainShape* lovrTerrainShapeCreate(float* vertices, uint32_t n, float scaleXZ, .z = -.5f * scaleXZ }; const JPH_Vec3 scale = { - .x = scaleXZ / n, + .x = scaleXZ / (n - 1), .y = scaleY, - .z = scaleXZ / n + .z = scaleXZ / (n - 1) }; JPH_HeightFieldShapeSettings* shape_settings = JPH_HeightFieldShapeSettings_Create(vertices, &offset, &scale, n);