Player pushing Boxes using bullet physics

Hello there.



Could anyone please tell me, witch is the most efficient way to deal with box pushing ?



Im using CharacterControl to move the character. Ive many ways to make the box, but none of em seems to work.

This is a little box snippet.



[java] protected void buildParts(float size, float x, float y, float z) {

Box b = new Box(size,size,size);

box = new Geometry("Crate", b);

box.setMaterial(Memory.getTextures().getMaterial("box", "flat"));

box.setLocalTranslation(x+size+(1-size), y+(size), z-size-(1-size));

box.addControl(new RigidBodyControl(0.5f));

//box.getControl(RigidBodyControl.class).setRestitution(1);

//box.getControl(RigidBodyControl.class).setFriction(0.2f);

//box.getControl(RigidBodyControl.class).setMass(0.1f);

masterNode.attachChild(box);

}[/java]



Thanx alot for any help !

Set the friction to close to 0 and maybe remove a bit of weight on the rigidbodycontrol.

Characters do not push the objects. Put a ghostObject around the character, check for overlaps and apply a force (probably based on walkDirection) to the overlapping objects.

2 Likes

Thanx for the answer.



My character does have a sphere collision shape, so i wouldnt need that ghostObject, is that correct ?

Also, would i need to make a ever lasting loop for all objects to check if the character is in range to push them ?



Something like

[java]

for(Object thing : mapObjects)

if(distance(thing, character) < 2f)

// push to moveDir

[/java]





In a big map with a good number of objects, wouldnt this cause lag ? Ima randomly generate dungeons with looads of pushable objects.

Thanx alot for your patience with newbies normen. U tha man !

You didnt understand Normen.

Add a ghostControl to the CharacterControl and then use a collisionListener.

1 Like
@KuroSei said:
use a collisionListener.

..or just check the overlapping objects, collision dispatch isn't assured to be triggered for the right objects.
1 Like

Sorry for not understanding my english is a little messy still, some words make sense to me but not the real meaning all the time, such as overlapping hehe.



So, if i have a ghostControl i can have a list of ‘overlapping’ (one ‘on’ another ?) objects, so i can check if my ghostControl is ‘on’ the box, so i could apply a force to facing dir ?



This means i wouldnt use the sphere collision shape for anything , i would use that ghostControl for everything ?

The box should have normal physics reaction to other objects (a normal RigidBodyControl) and also the ‘push’ effect with the player. Should i add 2 controls for it or switch controls for each respective action ?



Thanx alot for the help. Lovin jme.

You don’t have to go through all objects in the scene, if you put a ghost object arround you charakter you can just go through all objects overlapping with that and then decide if it is one of your boxes.
That way you just go through a very small ammount of objects each update, wich can be further minimized if you e.g. size the ghost object so it will not collide with your floor.

@ryukajiya said: You don't have to go through all objects in the scene, if you put a ghost object arround you charakter you can just go through all objects overlapping with that and then decide if it is one of your boxes. That way you just go through a very small ammount of objects each update, wich can be further minimized if you e.g. size the ghost object so it will not collide with your floor.

Are you answering a question from a year and a half ago?

<cite>@pspeed said:</cite> Are you answering a question from a year and a half ago?

Haha didn’t see it was that old :wink:
Somehow the forum showed it as new post…

1 Like