My Ninja character is floating after I replaced Oto with him

I used TestWalkingChar as the main class, and I replaced the Oto golem with Ninja, and set his stand stance to Idle1. This video shows this unfortunate accident.

Your collision shape is probably not not wrapped around your new model correctly, you’ll need to adjust the size/ y position of the Capsule Collision Shape.



EDIT Use this line, as shown in the tutorial, in order to see the collision shape the app is using

bulletAppState.getPhysicsSpace().enableDebug(assetManager);

after using bulletAppState.getPhysicsSpace().enableDebug(assetManager); i found the collision shape was on the ground and the model was stuck in it, with the center of his body suck at the top of the collision shape. i messed around with the y values in quite a few places in my main class and i cant work it out.

The center of the model is at its feet while the center of the capsule is at its center. Use a node to move the ninja down a bit. (No, I don’t have code, I cannot write code)

what node would i use? id assume its something like “model.move(0, -20, 0);”

i’ve looked through and experimented with the suggestions that come down after i type “model.” such as model.setLocalTranslation, setLocalTransform, setLocalTranslation. heres what the createCharacter method looks like



private void createCharacter() {

CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);

character = new CharacterControl(capsule, 0.01f);

model = (Node) assetManager.loadModel(“Models/Ninja/Ninja.mesh.xml”);

model.setLocalScale(0.05f);

model.addControl(character);

character.setPhysicsLocation(new Vector3f(-140, 2, -10)); <<was y15 from TestWalkingChar

rootNode.attachChild(model);

getPhysicsSpace().add(character);

bulletAppState.getPhysicsSpace().enableDebug(assetManager);



im sure moving the model down on the y axis is my only problem at this point, and i thought it wouldnt be anything more than something like “model.setLocalTranslation(0, -10, 0);” or “model.setPhysicsLocation(new Vector3f(0, -10, 0));”

Use a Node to attach the model to, move the model down a bit and attach the Node to the CaracterControl. If too hard do tutorials.

i cant believe im still stuck on this. could someone go into detail on what normen suggested? ive looked over the hello node, collision, physics, and assets tutorials again, looked up setLocalTranslation, move, and a few other things. i dont see why “model.setLocalTranslation(0, -10.0f, 0);” wouldnt work. the translations in the hello node tuts are structured differently as well.

Try this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

i didnt learn anything new from the scene graph presentation. im at the point to where i think i need to add something to “rootNode.attachChild(model);” but i dont know how id fit a coordinate in there. of course i may be completely wrong since i cant even recall one simple translation even after checking every tutorial for a way to move the model inside of the collision shape.

This is a guess…



[java]

// assuming you have a geometry/model/whatever named ninja

Node n = new Node();

n.attachChild(ninja);

ninja.getLocalTranslation().subtractLocal(0f,.05f,0f);



// Attach node n to the char ctrl…

[/java]



I believe that’s what normen was saying to do… don’t hit me if I’m wrong.

@snigglesnock said:
i didnt learn anything new from the scene graph presentation.

Thats too bad, you say you still don't know how nodes and children relate to each other?? Theres even code examples in the presentation. I really don't know how to explain it better. If you didn't understand this then copy and pasting this code will probably not help you either but whatever..
[java]
//create a node
Node node = new Node("ModelHolder");
//attach the model to the node
node.attachChild(model);
//move the MODEL down
model.move(0,-1,0);
//add the character control to the NODE
node.addControl(characterControl);
[/java]
Anyway I am staggered that this is such a problem, another guy got it in a second. If you ever understand this, can you give input on how the scene graph for dummies can be extended so you would have understood it? (serious request)
2 Likes

i apologize for not understanding, and i think my lack of basic java knowledge is whats screwing me up. firstly, i have a rough definition of a node, which i thought at first was the asterisks in the imports, but the scene graph slides gave me a good idea of it (when i said i didnt learn anything new i forget to mention ive seen it before and got only a rough understanding of it). another thing is that i dont know whether to put the Node stuff in createCharacter() or simpleInitApp() or both or neither. i really appreciate everyone’s help, and im almost relying on the forums because the problem im having doesnt seem to be covered in the tutorials. it’s also the whole node hierarchy thing and if i need to call the movement node before or after the model is loaded.



if someone can tell me how to put the node that moves the model inside the collision shape down and where the node code goes, im afraid youll have to explain it like youre teaching babies with half brains

Alright, I’m very new to JME and graphics in general so take this all with a grain of salt, but maybe I can try to explain.



I’ll try to start with the very basics and build up the way I understand it.



You wish to have a physics model for your character. There are various ways to do this which are supported by JME. One is you can have your character’s physics modeled by the actual graphical representation (by that I mean the polyhedron that you’re looking at). This seems natural, but like many attempts to make things realistic, it can lead to disaster. Unless you have quite a lot of sophisticated code for biped locomotion, your model is going to fall over when it tries to walk or even stand. If you wish to see this, you can give your model a dynamic mesh shape, and then try to move it by applying a force on it. The code by the way, for this, is something like (although this is incomplete)



CollisionShape player_shape = CollisionShapeFactory.createDynamicMeshShape(player);

RigidBodyControl player_physics = new RigidBodyControl(player_shape, 100.0f);



I do not recommend doing this, however.



It is more natural to model your character’s physics with a shape which doesn’t fall over, like a cube or something. The capsule shape provided is most definitely not the best solution to this problem for any model, but it is something which works pretty much ok no matter what model you’re using, and is pretty simple and straight forward.



Thus in your example video, the player IS standing on the ground with his physical representation (which is invisible). Your job is

to shift the player’s graphical representation so that he appears to be standing on the ground with his graphical representation.

(You could also try fiddling with the size and position of the capsule, but I’ll show you how to shift the player’s spatial)



I would arrange this like so:



You have a node to which you are attaching your model’s physics control, probably the root node.

You have a node to which you are attaching your model’s graphics “root node”, probably the physics control node.

You have a node which is sort of like the root node for your model’s graphics.



If your model only has one spatial, all you’re going to hang on the model node is the spatial, otherwise you might put more.



You then wish to shift the model downward. The best way to do this is to move the model’s graphics node, although if you only have

one spatial in your model you could also shift the spatial.



Now assume we are just attaching a character with one spatial to the root node:



Code (untested):

character_control_node.attachChild(whateverSpatialYou’reUsing);

whateverSpatialYou’reUsing.move(0,some negative number,0)



Your character control node is then attached to the root node.



Does this make sense?



We create a node, on which we hang our spatial, and then shift the spatial downwards.



The character control node is the node to which you add a physics control for the character, thus we are changing the relative locations

of the physics model for the character which the graphical representation of it.



If you wish to allow for more than one spatial on your character, add an additional node “character_node”, which you attach to character_control_node, and then attach your character’s spatials to character_node. You can have further nesting of nodes if you wish, but that’s another topic.



Thanks for this question, actually… I just realized I had this very problem myself and just fixed it by doing exactly what I showed you :smiley:

1 Like

Very clear description Tamago :slight_smile:

shakes head and leaves

1 Like