Elevator in jBullet?

Hi,



I'm currently working on implementing JBullet in my Game and it's working pretty good, but now i want to change the Elevators so they also use JBullet, but what is the best way to do this?



Right now it's working like this:

The elevator starts moving up/down as soon as a player collides with the Elevator. While moving the Elevator up and down it checks if there is a player colliding with it, and if a player collides with it, the player will also be moved up/down.



So now i thought, i just put the Elevator (it's just a Box) in a Physicsnode, check for collision and then just move the Elevator up/down. I thought the Player, who is standing on top of the Elevator-Box will be moved too, but apparently he isn't.



Is there something wrong with my Code or is it a Bug/missing Feature in jBullet?







And i got another question:

It seems to me as if jbullet has a problem when i use setLocalTranslation(Vector3f) instead of setLocalTranslation(float,float,float). Is it also just a bug in my Game, or is this a known Bug in jBullet?

If you want i can create a small Example, but i thought i just ask first before i create the Example :wink:





One last thing: Is there an "easy" way to extend PhysicsNode? Because in the Constructor of PhysicsNode, he already wants a Spatial, but i want to create the Spatial in the class first and then pass it to PhysicsNode. Do i have to create the Spatial first and then pass it to the class or is there another way so that i can create the object in the class? (while writing this, i thought maybe i can just copy the contructor of PhysicsNode, but that doesn't really look like good style to me, what do you think?)



Greets,

Dennis

Creativ wrote:
Is there something wrong with my Code or is it a Bug/missing Feature in jBullet?
I suspect your code is doing exactly what you are telling it to do.

When using PhysicsNode, if you create a node with mass of zero (a static physics object) then bullet does not update the world coordinates within it's simulation. Although you move the object, bullet never updates it's coordinates for that object (or elevator in this case) as it believes it's static, and by default static objects do not move.
I don't know if this is the case as you don't mention the details, but you can switch on the debug view (using '' when using the PhysicsDebugGameState), which will should bullet's interpretation of the world.
Creativ wrote:
It seems to me as if jbullet has a problem when i use setLocalTranslation(Vector3f) instead of setLocalTranslation(float,float,float). Is it also just a bug in my Game, or is this a known Bug in jBullet?
Neither.
Take at look at the source and you'll see no difference in the bullet-jme methods however there is a difference in the JME class Spatial between those two methods, that'll most likely be the cause.
Creativ wrote:
If you want i can create a small Example
That would be swell.
Creativ wrote:
Is there an "easy" way to extend PhysicsNode? Because in the Constructor of PhysicsNode, he already wants a Spatial

ermmm.... how about the default constructor?

public PhysicsNode(){

Hi,



I'm using a static Node (mass=0) for the elevator. So, as you explained, this will probably be the reason.

So what's the best way to create a Elevator, so that the Persons on the Box will also be moved?









I just tested it with the TestPhysicsCharacter.

If you replace line 98 with this:

character.setLocalTranslation(5,3,0);


It moves the Character as expected.
But if i use

character.setLocalTranslation(new Vector3f(5,3,0));


the Character just stays in the middle. It doesn't matter what values the Vector3f has, it always stays right in the middle.



hm....i somehow missed this Constructor :D Thanks!
I will test this tomorrow, but first i need some sleep :)

Maybe make an invisible platform with shape type Box, attach it to elevator, and use that for collision?

Thanks, I'll try this later.



I just tried using not a static node for the Elevator and set Gravity to 0, but it doesn't quite work.

The player on top of the elevator is moved with the box, but the elevator is still affected by the Gravity.



I set the Gravity like this:

this.setGravity(Vector3f.ZERO);


Is there a way so that the PhysicsNode isn't affected by Gravity?
Creativ said:

Is there a way so that the PhysicsNode isn't affected by Gravity?

Not until I implement the kinematic flag for PhysicsNodes. When its implemented physicsnodes will not be affected by physics but will affect other physics objects.

Ok, I added the kinematic flag to the svn version. Just create a normal physicsnode and do node.setKinematic(true);



Cheers,

Normen

Wow…that was quick :smiley:

Thanks! Works like a Charm.