Hello
I got a little problem trying to make the collision between the Ninja model and a TerrainGrid (generated from noise).
I tried this:
[java]CollisionShape terrainShape =
CollisionShapeFactory.createMeshShape((Node) terrain);
landscape = new RigidBodyControl(terrainShape, 0);
terrain.addControl(landscape);
PhysicsSpace().add(terrain);[/java]
I also put the debug mode by using this: bulletAppState.getPhysicsSpace().enableDebug(assetManager);
But when I start the application, the Ninja falls from the air to the ground passing through the terrain.
Don’t really understand why… By the way, I see a blue box around the Ninja but nothing around my terrain.
Thank you very much.
I guess you used a mesh collision shape for the ninja too, doesn’t work. Character, kinematic mode, kinematic rag doll are the keywords for you. The basic tutorials also contain a tutorial on the character.
Ok thank you, so even if the terrain has a mesh collision shape, nothing will appear by debugging ?
I used this for the Ninja:
[java]
private CharacterControl player;
private Node model;
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
model = (Node) assetManager().loadModel("Models/Ninja.mesh.xml");
model.addControl(player);
model.setLocalScale(0.05f, 0.05f, 0.05f);
player.setPhysicsLocation(new Vector3f(0f, 180f, -50f));
bulletAppState.getPhysicsSpace().add(player);
rootNode().attachChild(model);[/java]
@drweedy said:
Don't really understand why... By the way, I see a blue box around the Ninja but nothing around my terrain.
Yes that seems to be a quirk of jBullet that the debug mesh isn't shown for the terrain.
I guess it is possible that you might "tunnel" through the terrain if the ninja falls very far (i.e. moving very fast), you have a pretty high gravity which might cause this perhaps. Worth a shot at least.
Tried putting the Ninja really close of the terrain and it doesn’t change anything.
Is the collisionshape code for my terrain good or not?
Als, I use a TerrainGrid, could it be for something?
Thx.
EDIT:
Maybe should I use the “terrain.getGridTileLoader().getTerrainQuadAt(new Vector3f(0f, 150f, 0f)));” when I use createMeshShape.
But it doesn’t do anything,.
I found something :
I tried this : [java]RigidBodyControl terrainShape = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);
terrain.addControl(terrainShape);[/java]
terrain is a TerrainGrid object.
And the Ninja falls through the floor but stop at y = 0;
And “terrain.getHeight()” return 0.0 for every point of the terrain.
So it seems to be linked.
@jmaasing said:
Yes that seems to be a quirk of jBullet that the debug mesh isn't shown for the terrain.
Bullet and jme use a heightfield for the collision object, not an actual collision mesh (better performance). So it can't really render a shape to represent it as it is just a grid of height points, unless it did create a strip mesh but that wouldn't guarantee to exactly represent the actual terrain mesh and could be slightly misleading.
@Sploreg said:
Bullet and jme use a heightfield for the collision object, not an actual collision mesh (better performance). So it can't really render a shape to represent it as it is just a grid of height points, unless it did create a strip mesh but that wouldn't guarantee to exactly represent the actual terrain mesh and could be slightly misleading.
Yes, but native-bullet actually draw a blue strip-mesh in debug mode, although as you say it is not accurate it at least shows there is something there :)
So, no one knows how to make this TerrainGrid solid ?
Theres even examples doing it with physics. E.g. TerrainGridTileLoaderTest.
Implement TerrainGridListener in the class that does the physics stuff, and overwrite the methods to apply a collision shape for each added terrain when it’s loaded. Then use it to remove the shape when the tile is unloaded. You can’t generate a terrain grid shape, since the terrain grid isn’t static. You have to modify it every time a tile is loaded/unloaded.
Also I’m pretty sure you have to add and remove the collision shape from the physics space manually, I don’t think creating the control and adding it to the terrain is enough.
EDIT: beat…
Thank you very much ! I’ll take a look at the TerrainGridTileLoaderTest class later. But I tired it and it works fine
With this class and androlo’s explanations it would be good
Thanks a lot!
EDIT: Works fine !