Leadwerks C++ Noob here...
So I'm programmatically creating a bunch of floor tiles out of PolyMesh for my player to walk around on, and it works great except for one strange behavior.
When I call Translate() on my tile Model class it slowly erodes/squishes the PolyMesh data until it is gone completely, and then my player just falls through.
If I don't translate, no problem. I looked into the docs a bit and I see that PolyMesh isn't recommended for moving objects. However when I try the same with ConvexHull() I am getting no collision data at all.
My tiles are basically small flat planes created from 2 triangles to make a rectangle.
On create...
/*
* Generate a cTile
* ofs of entire tile position from center
* dim is width and length|depth
*/
Model* make_ctile(Vec3 ofs, Vec3 dim) {
Model* cmodel = Model::Create();
cmodel->SetColor(1., 1., 1.);
Surface* csurface = cmodel->AddSurface();//Surface::Create();//
Vec3 dn = Vec3(0, 1, 0); // up
csurface->AddVertex(-dim.x, 0, -dim.y, dn.x, dn.y, dn.z); // bl
csurface->AddVertex(dim.x, 0, -dim.y, dn.x, dn.y, dn.z); // br
csurface->AddVertex(dim.x, 0, dim.y, dn.x, dn.y, dn.z); // tr
csurface->AddVertex(-dim.x, 0, dim.y, dn.x, dn.y, dn.z); // tl
// CW
csurface->AddTriangle(2, 1, 0); // tr, br, bl
csurface->AddTriangle(0, 3, 2); // bl, tl, tr
csurface->Update();
csurface->UpdateNormals();
;
Shape* cshape = Shape::PolyMesh(csurface);
cmodel->SetShape(cshape);
cshape->Release();
cmodel->SetPhysicsMode(Entity::RigidBodyPhysics);
cmodel->SetCollisionType(Collision::Prop);
;
cmodel->Translate(ofs);
return cmodel;
}
On update...
for (int i = 0; i < tilex; i++) { // Pull tiles
tiles[i].tile->Translate(0, 0, tile_speed);
}
Included is a view of the collision working when there is no translation, and also a view of the collision failing after translation has started.
I also included a screenshot of the output when I use ConvexHull to generate the shape, which seems to not have any collision data whatsoever.
Shape* cshape = Shape::ConvexHull(csurface);// PolyMesh(csurface);
I'm not really sure what to try next.