Hello everyone
I am trying a bit with mesh character and and mesh ground. I am using the southern David glb and its functions from the playground and added my terrain mesh.
Playground is here: https://playground.babylonjs.com/#WF4P7M#24
I tried with other format and groundfromheightmap, but the only way i got the terrain and other meshes on it as i want was with glb. So im trying to stick with it.
I want the character to walk on this terrain, i added the terrain and character to the babylon editor, where he is walking on it, but im having trouble adopting it to the playground. I searched some questions, but none was similar. I tried some solutions from questions with collision (different kind of physic engine, righthandrules…), but they also didnt bring the result i wanted. So can anyone give me a hint what i am missing?
Thank you in advance
Hello docEdub
Thanx for your reply. I checked the navigation mesh, but will i be able to control my character with keyboard and not with mouse on the mesh?
I tried some other ways, for example i read that a groundbyheightmap can be also created with vertexdata, so i found a playground that extracts the vertex and clones the mesh, so i thought i can push these vertex into the vertexdata.groundbyheightmap, but it doesnt clone my mesh: https://playground.babylonjs.com/#AXHXAQ#4
another attempt im on now, is to actually go back to a heightmap create a ground with it and add the texture and buildings: https://playground.babylonjs.com/#0D883E#332
so here i at least got the physics working, although not properly yet.
But the problem i have with the heightmap is, it seems only reading png and jpg (integer) and the tif i have with floating doesnt work, so the ground is quite bumpy. so i would prefer to use the first variant , to use my complete glb mesh and add physics there.
Your first playground is mixing physics with moveWithCollisions, which is not good as these two systems will conflict. I recommend taking a look at this great thread by @potato_noob Physics air walking - Questions - Babylon.js (babylonjs.com) which is using Havok Physics for movement and has a lot of great insights.
2 Likes
Thank you for that hint, didn’t think about this Collision ↔ Physics issue.
So i should go either for physics or collision right? I checked the Guided Tutorial Game creation and thought the raycast might be a good way, since for me its actually enough for my player to walk around the mesh.
But in my Playground it doesn’t take my mesh as a ground: https://playground.babylonjs.com/#WF4P7M#33 seems it doesnt get “grounded”.
Is it possible this way with my mesh? Or do i need to createGround? I have to say im always not sure if its my missunderstanding of the need of proper ground creation or a mesh can be the ground, since there are these functions createground, creategroundfromheightmap and heightmap collision.
Raycast should work normally with your mesh as ground. Can you try simplifying your example a bit more?
Ok, i cleaned up: https://playground.babylonjs.com/#WF4P7M#35
All controls and additional settings.
Or did u mean the mesh? With my meshes I sometimes also have issues with loading them, but I think it should be completely loaded when the character appears.
I’m not seeing any player in your example? Also you should really guarantee your ground mesh is completely loaded before trying to raycast.
Jea im reading more about this and continue trying.
But since u posted the link, i also wanted to tryout the playground you just recommended. So i put my mesh in there, the player actually reacts and also doesn’t just fall. I changed the PhysicsShapeType of the aggregatedground to MESH. I didn’t change anything else, but in the end he still doesn’t walk on the mesh.
You can create a very simple simulation with physics, like this: Character Import and animation | Babylon.js Playground (babylonjs.com), however, when the ground is not flat, it’s going to be hard to move the character without them falling over. We have an idea to do a PlayerController for next release to make this work easier: [Physics] Player controller · Issue #13796 · BabylonJS/Babylon.js (github.com), but we haven’t started development yet.
1 Like
Ah, that’s good to know. So this also means with cannon, omoi and ammo physics I won’t get the character walk on it? Then I will focus on the ray and try to get it working with collisions for now and wait for further development, I guess with this also car and other vehicles can be included, which would be awesome on a terrain/mesh like mine.
You can get the character to walk using any of the physics engines, it’s just going to require more work.
1 Like
Totally agree
This is a recurring topic.
Working with movewithcollisions without physics forces us to do tricks and look for fixes to keep our character on the surface.
In some cases it is more than enough, especially when you want your character to simply move on a flat surface, without ramps, stairs or jumps.
Thank you for the replies, especially carol.
i got a box now moving on my surface, so i will build on that and get more into this physics.
regards
With carols hints i went a step back and figured out, that AmmoJS works quite good with my terrain and i managed to get a sphere moving on it. among all i found this nice thread (especially wingnuts long comments with lots of ideas and thought enlightened me quite some time) and adopted some parts and i like that the sphere is stable moving on my ground: https://playground.babylonjs.com/#WF4P7M#42
After the sphere sliding quite hard on my terrain i thought setting mass to 0 might be a good workaround.
So my idea is on keydown mass changes to 1 and on keyup it changes back to 0, so there wont be any sliding. its working, but now i got 2 problems which i didnt manage to solve. First is when stop pressing key while sphere is meant to fall, its of course stuck up there and second, when i push two buttons and stop pressing one sphere also stops.
The First problem i thought about using the raycast after keyup and make a while loop until the sphere is on the ground. But it didnt really loop. I also tried to wait for collision after keyup and then sets the mass to 0, but then somehow the sphere was stuck. Pressing “wasd” didnt change mass back to 1.
Second Problem with the two or more buttons i tried to solve with counting pressed buttons, i expected it to count only when pushing the button, but jea it counted like every 0.1sec while pushing.
Well, if anyone has an idea would be glad to hear. I know the problem is not mesh falling through mesh anymore, but i thought if someone tries with a mesh like mine, he might end up with same problems.