Player sliding in-between two objects on voxel world

Good day, I’m a software engineer and I’ve jumped into jmonkeyengine, I’ve built a simple voxel world (a collection of cube objects exported from Blender. This is the initial cube with a simple textured wrapped around the cube).

In the game, all works fine until you try to walk in-between two objects,

here is an example of what happens:

the player slides to the center of the cube being pushed by all of the surrounding cubes.

Currently the player has a CharacterControl built with:

CharacterControl control = new CharacterControl(new CapsuleCollisionShape(1.2f, 0.2f), 0.1f);
    control.setFallSpeed(fallSpeed);  -> 30
    control.setJumpSpeed(jumpSpeed); -> 10
    control.setGravity(gravity); -> 30
    control.setPhysicsLocation(initialPosition); -> [0f, 0f, 0f]

and added to bullet state:


The objects are in waveform .obj format with a material attached. This is a 1x1x1 cube that is scaled down to 0.2 units as such:

Spatial cube = assetManager.loadModel(cubeName);
    cube.setLocalTranslation(position); -> [0f, 0f, 0f]
    cube.setLocalScale(cubeSize); -> 0.2f

With a RigidBodyControl:

RigidBodyControl rigidBodyControl = new RigidBodyControl(CollisionShapeFactory.createBoxShape(cube), 0f);

and each voxel is added to bullet:


This system works perfectly when creating cubes using the Box model located inside jmonkey, the player can move freely. So I assume that there is different behaviour when using a Spatial over a Box type with RigidBodyControl. Or the capsule collision with the rigidBodyControl is pushing it around like a magnet.

What is my best plan of action? Should I attempt creating some collision mesh? Would it be better to create a box and somehow UV wrap it inside of jmonkey dynamically?

Perhaps there’s a setting i’m missing somewhere?

Any help would be very much appreciated, thank you!

Just a tip: block worlds are not made of cubes. They are made of visible faces.

This is great advice, thank you!

If I go down this route, this will likely fix my problems

You will find lots of topics in the forum on this subject. There is even an open source library someone wrote already if you are looking for a start or just for inspiration.

Thank you, i’ll do some digging :slight_smile:

Seeing that you’re a core developer, mind telling me what the issue might be with this sliding for future reference? I’m curious to if it’s the capsule vs the cube meshes perhaps.

Does it still occur if you turn vsync on?

I just gave that a shot with;

and I’m still sliding to the center of the face.

That won’t actually set anything until you reset the application.

Easier just to set vsync in the settings dialog or in the app setting before you even start the application.

…else you probably aren’t really testing it.

Ah yes, of course, in the dialog vsync was enabled by as my default settings. I also tried disabling vsync to no change in this effect.

Then i guess the triangles are too large compared to the collison shape you are using. But as paul mentioned, what you are doing is not the best way to create a voxel-based world. Search isosurface on the forum.

I agree, the triangles are definitely the problem here. They’re forcing the collision shape into the center of the quad.

I’ve checked out pspeed’s implementation of isosurface and the post of course; this seems promising, i’ll see if I have the coding balls to implement this. Looks like I’ve got quite a bit left to do for some terrain :wink:

Voxel terrains are deceptive. They look so “simple” compared to the smooth curves of a well tesselated mesh/heightmap terrain, but from what I hear they’re some of the most challenging to implement.

I agree, the simplest things are often the most difficult to figure out. I’ll give it my best shot, I’m sure it’ll end up being a fun project to work on for the next couple of months. Luckily my life doesn’t depend on these voxels (yet!).

1 Like

Is your intent to render a block world similar to games like Minecraft or real IsoSurfaces like in my demo?

Vastly different things and your first post made it seem more like a block world game.

Very much more in line with minecraft’s block world. I assumed you used a grid of seperate terrains to populate your world.
I attempted a go at creating flat faces instead of cubes; I tried creating Quads, Planes and finally after being unable to set the position/size of the plane and not able to attach a RigidBodyControl to the Quad I settled creating a Plane inside Blender instead.
The problem of course still persists.

There is already an open source block world library written for JME. I believe it also already integrates with bullet. I can’t remember what it’s called off the top of my head but should be easy to find and probably others will chime in if not.

Edit: and on this topic, I know a little bit about the subject…
(But I did my own code and didn’t use the aforementioned library.)

If you want know more about voxels in general is a pretty good resource.

As something for myself, i’d like to go down the rabbit hole and see if I can get something working without using the library, but I am wise enough to read through the whole thing and probably play around with their implementation before I bump my head too many times.

Mythruna is pretty great, although, much much larger than the project i’m hoping to achieve here.

I did a 10 second search and found this thread: Cubes – A Block World Framework [Update Preview]

…somewhere down that rabbit hole is the source code you are interested in taking inspiration from.