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 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));
rootNode.attachChild(terrain);
getPhysicsSpace().add(terrain);
//source code just uses space not sure if getPhysicsSpace is what I want
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.
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
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.
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.
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ā.
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
My new plan actually is to learn about Rays and Bounding Boxes.
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)
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.