Node won't move

Hey guys, I have a simple yet annoying problem.

I am testing for a few months jMonkey and now I wanted to start a new test project. Just a simple stuff for the moment : I have a class Character, which represents a character. It is a child from a Entity class, which represents… well any entity that appear physically in the game world.

An Entity has a protected variable, called graphicForm, which is a Node. This will represents the graphic form of the Entity. When I set this node to a simple box from inside the Character Entity and add it to the app root node, the box does appear.

Here is the problem : when somewhere in the code (after I set the graphicForm and added it to the root node), I say :

[java]this.graphicForm.setLocalTranslation(new Vector3f(
this.graphicForm.getLocalTranslation().x,
this.graphicForm.getLocalTranslation().y,
this.graphicForm.getLocalTranslation().z + 1.0f));[/java]

The box won’t move ! I tried to debug and AFTER I set the graphicForm variable and add it to the root node, I wrote :

[java]System.out.println(this.graphicForm);[/java]

It prints “null”. The box appear but in fact does not exist ? What the hell ?

Any ideas guys ? Thanks !

Are you calling System.out.println(this.graphicForm); from inside the Character Entity class?

As you talk about “physically” I guess because you attached a physics control.

@kwando said: Are you calling System.out.println(this.graphicForm); from inside the Character Entity class?

Yes, indeed.

@normen said: As you talk about "physically" I guess because you attached a physics control.

It’s just a test for the moment, I don’t have implemented the physics yet. I meant “any entity that appears GRAPHICALLY in the game world”

The box won’t move ! I tried to debug and AFTER I set the graphicForm variable and add it to the root node, I wrote :

Did you try to put that code in the update method? Edit: Or more precisely somehow let it be run by the update method of the application class.

It prints “null”. The box appear but in fact does not exist ? What the hell ?

I think it just prints null because you did not give a name to the node (graphicForm). So the name String of the node is null.

1 Like
@naas said: Did you try to put that code in the update method?

WELL. You know what guys ? I am a fucking jerk. I thought the whole Entity list that I added in my app was parsed and every Entity has its “update()” function called. This function would set the Entity’s local translation if needed. And I forgot to call this function in the iterator. Just a simple :

[java]element.update();[/java]

I added it. It works now. I feel so stupid.

@naas said: I think it just prints null because you did not give a name to the node (graphicForm). So the name String of the node is null.

Yeah, and I used [java]… = new Node(“someNodeName”);[/java] instead of just [java]… = new Node();[/java] and it prints the Node’s name now. This was confusing me, I thought a println would print some memory shit to say “hu yeah, this Node represents something in memory but I can’t translate it into a string, you know”, just to see if the Node does exist.

In fact it now prints the Node’s name, as you said. Great !

Have u tried printing out the local z translation before and after? and put a breakpoint on that code to make sure it is infact executing.

Edit: nvm

@caporaltito said: and it prints the Node's name now. This was confusing me, I thought a println would print some memory shit to say "hu yeah, this Node represents something in memory but I can't translate it into a string, you know", just to see if the Node does exist.

In fact it now prints the Node’s name, as you said. Great !

Glad to help :slight_smile: Actually this confused me a few times too^^ It’s because the toString method of Spatial (which Node extends)

[java]@Override
public String toString() {
return name + " (" + this.getClass().getSimpleName() + ‘)’;
}[/java]
So if you look at your println closely you should see something like “null (Node)” not just “null” this is how you can tell that the Node object does exist.