Trouble with pick up something

Hello there,
Im trying to create a forklifter simulator, where you pick up a pallet. The problem is, that sometimes the forks moving through the pallet. Ive made a short clip.

I use multiple box shapes added in CompoundCollisionShape for the pallet and the fork. Thats my code for the pallet:

        debugmodel = assetManager.loadModel("Models/eup/eup.j3o");
        debugmodel.setLocalTranslation(12f, 0.5f, 12f);

        CompoundCollisionShape sceneShape = new CompoundCollisionShape();
        // four corners
        BoxCollisionShape box_ground = new BoxCollisionShape(new Vector3f(0.11f, 0.11f, 0.11f));
        sceneShape.addChildShape(box_ground, new Vector3f(0.6f, 0.11f, 0.85f));
        sceneShape.addChildShape(box_ground, new Vector3f(-0.6f, 0.11f, -0.85f));
        sceneShape.addChildShape(box_ground, new Vector3f(-0.6f, 0.11f, 0.85f));
        sceneShape.addChildShape(box_ground, new Vector3f(0.6f, 0.11f, -0.85f));
        // top plane
        BoxCollisionShape box_top = new BoxCollisionShape(new Vector3f(0.71f, 0.02f, 0.94f));
        sceneShape.addChildShape(box_top, new Vector3f(0, 0.24f, 0));
        RigidBodyControl item_phy = new RigidBodyControl(sceneShape, 0.1f);


And this is the part for the forks from the vehicle. The forkerFrontPart is a ChildNode from the main vehicle:

        forkShapes = new BoxCollisionShape[2];
        CompoundCollisionShape box_forker = new CompoundCollisionShape();
        // bottom plane
        box_forker.addChildShape(forkShapes[0] = new BoxCollisionShape(
                new Vector3f(1.15f, 0.1f, 1.8f)), new Vector3f(-0.0f, -1.15f, 1.95f));
        // back plane
        box_forker.addChildShape(forkShapes[1] = new BoxCollisionShape(
                new Vector3f(1.15f, 0.8f, 0.1f)), new Vector3f(-0.0f, -0.45f, 0.15f));
        RigidBodyControl fork = new RigidBodyControl(box_forker, 0);

I tested to make the pallet bigger, but same result. Its bouncing sometimes or jumping out of the map.
Any Ideas to solve this? Are there better solutions to make a collisionshape for this things?


certainly you are setting lifter’s position directly, instead of using applyforce, so your lifter does not smoothly move upwards, instead it teleports every step some amount upwards, causing palette to overlap your lifter slightly.

try use setLinearVelocity or applyForce. i dont know how you can do it only for part of a model, but you should never set physical object position directly for movement or rotation
maybe you should try
forklift’s lifter can be described pretty good as “pulley chains” for purposes of jme3 physics i think

edit: palette must be able, through collisions, to stop lifter even if lifting key is pressed. for example ceiling must be able, through palette, to stop lifter. this is automatically solved when you use applyForce.

edit2: it looks to me, you setting forklift’s physical position directly too. you should move forklift by using applyForce too. it becomes more complicated and you probably will rewrite whole code because of this

Just to give you a better understanding of how collision shapes are handled:
Using this example create 2 boxes that overlap each other - they will sort of explode (because they ‘dont want to’ be one inside another). That is what happens in your app.

thx for answer. I tried to used applyForce and setLinearVelocity for the forks, but nothing happens. Maybe I think for using this its necessary to set a mass and disable the kinematic mode.
But when the kinematic mode is disabled, its falling to ground. Maybe I should add the forks like a driver to the vehicle (similar

Edit: ok I tried setLinearVelocity again, but its only moving the complete vehicle :frowning:

going back to your original code, a few other things to try is to make your item_phy heavier, at the moment it is only 100g. Also try give your fork a mass as well.

I give the item_phy 20kg and the fork 40kg, but no better result. I tested also some joins between the fork and a new node to pull, but its hard to fix that forks. Maybe a reason is that the forks and the pallet are scaled (to 0.4f)?
When kinematic mode is activated, the only way to move it is setLocalTranslation. ApplyForces and setLinearVelocity are not working.

Ive no idea whats the correct solution for this problem. I will try to set a child node for the fork and add the pallet by collision.

@daywalker said: When kinematic mode is activated, the only way to move it is setLocalTranslation. ApplyForces and setLinearVelocity are not working.

Curious… what did you think kinematic mode did?

Since physics don’t apply to it, it’s kind of for static stuff.

yes i know. Ascaria says I should try this, but of course there is no effect.

i think you take difficult thing to start with, lets try some easier things first, split it into indivisible things …

you will learn about pitfalls and limitations
after a month or two, you can create great forklift :slight_smile: and in year or two a whole game :slight_smile:

ps: i never did one model with moving physics parts, so i cannot give you more hints :frowning:

Fork lift is actually a demo in the Bullet physics source code

Maybe not so easy to read but it shows how to use joints and motors to make a fork lift. You should not set anything to kinematic and as @ascaria says, never setPhysicsLocation because that throws all physics calculations out the window and you might as well not use physics at all.

yea, when you get rid of physics at all, as @jmaasing says, then you could do some test if palette collides with forklift using for example raycast and then simply attach palette’s spatial to forklift lifter’s node

but then it is up to you to do all movement by yourself