Quick question about creating model

I don’t understand why the uncommented code works fine as far as animating the object (changing location and rotation using AnimationTrack) and the commented code will result in the object restarting every time from the initial location (0,0,0) before animating? This function is only called once at the beginning and then the animation code is called after (I use animationTrack)


/** function that creates cars called from Jme3CreateEvent /

public void create3dModel(String id, String type,

float x, float y, float z) {

Box drive_unit = new Box(new Vector3f(x, y, x), 1, .25f, .5f);

mySpatial = new Geometry(id, drive_unit);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat1.setColor(“Color”, ColorRGBA.Orange);




if (assetManager == null) {

System.out.println(“WARNING: Asset Manager is null”);


mySpatial = assetManager.loadModel("/Models/" + type + “.obj”);

mySpatial.setLocalTranslation(x, y, z);






note that the object is initially created in the right position (e.g (4.0,0) and then when I animate it to go to let’s say (7,0,0) the object does that from (0,0,0) only using the uncommented code

Try setting the center of the box to (0,0,0) and using box.setLocalTranslation(x,y,z) to get an accurate test. Then step through the debugger and see what is changing the values.

To make the box the same as your model, you want to set the proper translations. If you don’t do that then your test is not accurate. Right now the box is always going to be offset because of the center value you set and the animation is going to set the localTranslation.

The box’s initial translation is (0,0,0) while the model’s initial translation is (x,y,z)

ug, listen. Of course the issue is not the box. But your test is meaningless because the local translation of box is not set. Set the center of the box first to (0,0,0) then set its local translation to (x,y,z). The animation sets the translation of the models, not the mesh values (which is what the center of the box is: mesh values not translation)


[java]Box drive_unit = new Box(new Vector3f(x, y, x), 1, .25f, .5f);[/java]

This line does not move the box, it creates a mesh that has an offset of x,y,z. The center might even be outside of the actual visible box.

See this:


look, do this:

[java]Box drive_unit = new Box(1, .25f, .5f);


first, then re-run the test. Then we can see what the issue is