It could mean so many things. So I’m going to assume one of them and reply: IMMEDIATELY vacate the building you are in because your machine is about to explode!!!
Ok… it probably wasn’t that one. Which of the literally millions of ways of “not working” is it? Does it crash? Does it blue screen your computer? Does nothing happen? Does it throw an exception?
The CollisionShape is not updated but left empty ( some times one of the faces works but i could not find out on which condition).
See the effect in this video:
One thing I see in your code is that when you add the rigid body to the tile then you only add the control when it has visible faces. If it didn’t have visible faces the first time then there will never be a control.
Also, if it does have visible faces the first time then you add the control twice in the second case.
This seems like something that could easily be sorted out with some logging and/or a session in the debugger. The logic is definitely strange… which may or may not be the cause… but you having better awareness of what is actually happening in the working and non-working cases would be beneficial anyway.
in physicspace ____ has visible faces
1______________1______________update
1______________0______________remove from physicspace
0______________1______________add to physicspace
0______________0______________do nothing
As text:
If the tile is already added to the physicspace and has visible faces -> update collisionshape
If the tile is already added to the physicspace and has no visible faces -> remove from physicspace
If the tile is not added to the physicspace and has visible faces -> add it to physicspace (and update)
My code
[java]
public static void updateCollisionShapeOfTile(final Tile t) {
if (t.getRigid() == null) {
logger.log(Level.WARNING, “No rigidBody; Adding now”);
RigidBodyControl rigid = new RigidBodyControl(0);
t.setRigid(rigid);
}
if (t.hasVisibleFaces() && t.getRigid().getPhysicsSpace() == null) {
System.out.println("vis nospace");
if (t.getGeometry().getControl(RigidBodyControl.class) == null) {
System.out.println("geometry has no rigidBody "+t.getRigid());
t.getGeometry().addControl(t.getRigid());
}
instance.physicSpace.add(t.getRigid());
} else if (!t.hasVisibleFaces() && t.getRigid().getPhysicsSpace() != null) {
System.out.println("!vis space");
instance.physicSpace.remove(t.getRigid());
}
if (t.hasVisibleFaces() && t.getRigid().getPhysicsSpace() != null) {
System.out.println("vis space");
if (t.getGeometry().getControl(RigidBodyControl.class) == null) {
System.out.println("geometry has no rigidBody "+t.getRigid());
t.getGeometry().addControl(t.getRigid());
}
final CollisionShape shape = CollisionShapeFactory.createMeshShape(t.getGeometry());
t.getRigid().setCollisionShape(shape);
}
}
[/java]
But it doesn’t work as well…
I was working on my tile paging until now but this works quite good so i will focus on that problem now.