(SOLVED) How to make terrain solid (RigidBodyControl)

Hi all,

I am working on getting a character moving across some ground and I am pretty stuck. I just cannot seem to figure out how to make my ground solid. I made my terrain just in the jMonkey SDK.

I am working on this 3rd person camera source code (TestPhysicsCharacter).

That code uses TestWorldSoccer from the PhysicsTestHelper.

In the soccer part of the code we have this section

 public static void createPhysicsTestWorldSoccer(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
Box floorBox = new Box(20, 0.25f, 20);
        Geometry floorGeometry = new Geometry("Floor", floorBox);
        floorGeometry.setLocalTranslation(0, -0.25f, 0);
//        Plane plane = new Plane();
//        plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
//        floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
        floorGeometry.addControl(new RigidBodyControl(0));

I am able to use that^ code and hop happily around on the cube to my heart’s content but I just cant get my created terrain to work. When I load up I drop through it into the abyss of jMonkey space. can someone try to point me in the right direction please? I’ve been reading and trying all the stuff that I can find-sorry if I missed something obvious.

My current code:

 // init a physical test scene
        Spatial terrain = assetManager.loadModel("Scenes/1234.j3o");
        //Plane plane = new Plane();
        //plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
        //terrain.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
        terrain.addControl(new RigidBodyControl(0));
//source code just uses space not sure if getPhysicsSpace is what I want 
1 Like

I am pretty sure your code looks correct. Does the issue happen with all of your terrains, or just this one?

I have experienced the same issue with specific terrains, especially on older maps where I’ve saved/loaded its terrains a lot. (I only just re-introduced physics into my game with Minie, so I am still occasionally discovering certain terrains on my old maps that have this issue)

I’m fairly certain this is some sort of bug with terrains that I’ve been meaning to make a post/issue about actually, so I’m curious to know if the physics works with the same code when you try with a fresh new terrain.

If so, then a temporary workaround I plan to do is to just re-make my broken terrains with the broken terrain’s height map data and material; but discovering the underlying cause if this is a bug would also be good.


hey donuts!

I did a little detective work and it happens with all the terrains that I make, which is just in the basic simple way here:

Right click Scenes (Empty jme3 scene)
Name it something desperate (click Finish)
Right click (edit Terrain)
select scene root and click (add terrain)
select terrain size (total/patch)
heightmap (flat)
alpha blend texture size (Finish)

I’ve tried messing around with various things like adjust the total size, trying out a hill, making the character model larger etc. Yeah I’m not sure if I’m just not doing something properly somewhere or if it is indeed a bug in which case at least I can replicate it 100% of the time :face_holding_back_tears:

(cough) well looks like there is at least some user error going on here

I had thought that it was a material line but I added LocalTranslation to my little code block and now my guy sits on the ground… :melting_face: :raised_hands:

Ima be messing with this at least for a while here though so I will keep my eyes peeled for anything odd going on that I notice

      Spatial terrain = assetManager.loadModel("Scenes/newScene.j3o");
                 terrain.setLocalTranslation(0, -5, 0);  //Important :^)

                     terrain.addControl(new RigidBodyControl(0));

Maybe your avatar or whatever started below the terrain and so fell right through?

…could be you need to send a pick ray straight down where you want to place him so you know how high the terrain is there.


I’d also suggest doing something like respawning the player if they’ve fallen through the world, since falling through the world is something that can still occur for other reasons, like if there’s a big lag spike when you spawn npcs right after the map loads. I tried doing extra things to make it not happen (and could still do more), but I still always find edge cases where an important NPC is missing because they somehow fell through.

I like to check for all my Players’ and NPCs’ Y value and then I force respawn them if it gets to a really low altitude. I’ve watched a lot of youtubers and streamers who play new releases and Indie Games on steam, and I notice they always like to try to find ways to break the game, and infinitely falling through the world is always the most common trick they manage to find right away, whether its from walking off the edge or finding a spot to clip through. And I’m always surprised by how many games released on steam don’t use this simple trick (or anything similar) to just reset the player / npc when they fall to an unrealistically low y value, since things like that can be the determining factor between whether the player keeps playing or alt-f4s and calls it a bugged game.

Having a fly mode also helps a lot for debugging these issues, so when you fall through, you can fly up and down and around to see if you can trigger the physics interaction in another point.

1 Like

In the new Mythruna engine, I use this “bug” all the time to test things that are easier to test if I can start walking through solid terrain. :slight_smile:

Soon I will have to start clamping down on the causes and may have to give myself a tool to warp myself into blocks.


I lucked out, because I “accidentally” gave myself a tool for this when I made a fly mode, so the idea wasn’t even intentional on my part.

If the player holds the fly-down button while on top of the terrain, they coincidentally move fast enough to get pushed through the terrain (thanks to my light weight, janky physics system I made for simulating player movement with simple Rays) This also means I can’t let players use fly mode or they can fly through anything they want, but I wasn’t planning on that anyways thankfully lol.

1 Like

Yeah, in my case, I still have a “super run” enabled that moves faster than the physics engine can handle but is fine if you are flying over large distances. But the more controlled way is to just place blocks on yourself.

Still, now that I have scriptable tools then I can give myself a developer tool and close off these ‘features’.


Visually it looked like he was plopping on top but my locations of things certainly could have been messed up.

good concept to think about …

Thanks for the input and have fun with your own shenanigans haha. :melting_face:

i dont know exactly what you want to achieve.

But you know that you have JME tests (jme3-examples) package where you can compare.

for example(idk if good example):

This is walking character on terrain if im not wrong.

Yes, that is a good example as that was what I was going to try next (that is with animation- I was trying the one without animation first for simplicity).

I am really just messing around with making things ‘solid’ so that my character can run around buildings and such but not pass through them :ghost:

My new plan actually is to learn about Rays and Bounding Boxes.

Thank you for the suggestion oxplay :melting_face:

1 Like

I dont know if it is solved, but try moving/warping the chatartercontrol/object to say, like 100f/200f or something like that. thenn see if you fll on the terrain(I once had a similar issue, because my character started below the terrain)

1 Like

I was able to fix this I forget my exact error but I think my capsule collision shape was too large for my model and it was actually loading so that the bottom of it was below the terrain. Not sure if that was exactly it but something like that, so I guess I was below the terrain as well haha.