PhysicsSpace deletes objects?

When I load a model as a Spatial, attach it to a PhysicsCharacterNode, but do not call getPhysicsSpace().add(Object obj) it works and responds to key bindings as intended. However, when I call getPhysicsSpace().add(Object obj) and try to move the model, jME3 actually deletes the object from the scene. (It goes from 16 objects, 46 uniforms, 3184 triangles and 9078 vertices to 15 objects, 44 uniforms, 474 triangles and 948 vertices) Is this a bug with PhysicsSpace  responding to transformations or are there methods to fix this?

Well, maybe you move the object out of screen? Then the counts will go down as well.

I don't think it's just moving it out of view, because when I press the A and D keys (which just turn the model), it disappears as well.

So you load a model. Are you sure the center of the model is where you expect it to be visually? Because if its not you might just move it out of sight by just turning it.

Maybee it is just falling out of view?



try System.out.println(object.getWorldTransition();

I had a similar problem, i was applying a scale to my terrain physicNode after adding it to physic space.

the result was that the terrain was scaled on screen but not in physical space, so at one point my character was falling through the "displayed" terrain and thus disappear from view.

I don't know if its a bug, or if it's a normal behavior, but i solved it by applying the transformation to the spatial before creating the physicNode and adding it to the physic space.



Maybe you are in a similar case.

Empire Phoenix said:

Maybee it is just falling out of view?

try System.out.println(object.getWorldTransition();


I tried that, and it seems the model is translating very quickly in addition to whatever transformations I'm applying (rotation in my tests). Maybe I need to adjust the gravity so the model doesn't translate when it shouldn't?

nehon said:

I had a similar problem, i was applying a scale to my terrain physicNode after adding it to physic space.
the result was that the terrain was scaled on screen but not in physical space, so at one point my character was falling through the "displayed" terrain and thus disappear from view.
I don't know if its a bug, or if it's a normal behavior, but i solved it by applying the transformation to the spatial before creating the physicNode and adding it to the physic space.

Maybe you are in a similar case.


I don't think that would be feasible, since the transformations are applied on key presses instead of upon initialization.
Tavyr said:

I tried that, and it seems the model is translating very quickly in addition to whatever transformations I'm applying (rotation in my tests). Maybe I need to adjust the gravity so the model doesn't translate when it shouldn't?


So your object is obviously falling just as it should do in a physics space :)
You can use getPhysicsSpace().setGravity(vector); to adjust the gravity of the physics space, its earth gravity by default.
normen said:

Tavyr said:

I tried that, and it seems the model is translating very quickly in addition to whatever transformations I'm applying (rotation in my tests). Maybe I need to adjust the gravity so the model doesn't translate when it shouldn't?


So your object is obviously falling just as it should do in a physics space :)
You can use getPhysicsSpace().setGravity(vector); to adjust the gravity of the physics space, its earth gravity by default.


The object is also moving along the Z-axis virtually instantly, in addition to falling (like it should). I'm not sure about gravity in 3 dimensions, but I don't think it affects the Z-axis.

normally only y axis, but if yous et the gravity yourself it can be any direction…


But even if I set the gravity to (0,0,0), the object still moves in both the negative Y and positive Z directions. In addition, a bit more information about the object itself. The object is a Spatial loaded from an mesh.xml file, attached to a PhysicsCharacterNode. The turn and move methods I'm using are adapted from the FlybyCamera's turn and move methods.  Maybe it's something in those?

PhysicsCharacterNode



thats it 1. its not a realy physical object

2. only primitive shapes are supported (that correct normen or?)

Okay, so since it's not a real physical object I thought it was behaving erratically. I attached it to a normal PhysicsNode instead and it works fine, except gravity won't apply while it's transforming  :| Perhaps I need to implement the KinematicCharacterController in some other way?

I dont get what you mean by "gravity doesnt apply while its transforming". If you set the location of course it will not fall, it will be put where you said it should. I think what you want to do is add forces instead. If it was a PhysicsCharacterNode and it moved in z-direction then you probably set the walkDirection to 0,0,1 which makes it move. Its a constant move vector, set it to zero if your character shouldnt move.

What I meant by "gravity doesn't apply while it's transforming" was that when I held down any of the bound keys, the model would keep its current height until I released the key, at which point it would start falling again, but that can be fixed with forces. As for the PhysicsCharacterNode, I don't see any way to apply a force to it, but all of the tests that use it add a vector from a camera on binding instead. I'm thinking I should use the PhysicsCharacterNode for the jump method. What would be the best way to go?

There is no forces with PhysicsCharacterNode, its just got the walkDirection vector. Its not real physics as stated.

Okay, I think I've got it now XD I just need to get the attached spatial to move with the node now.

Tavyr said:

Okay, I think I've got it now XD I just need to get the attached spatial to move with the node now.

Yeah, sorry, might be that somethings bugged there, dont know whats wrong right now, its also not working in the test :/

I had the same issue actually, with an attached Spatial not working with PhysicsCharacterNode. I fixed the issue in SVN.