Node won't rotate

Hello all,

I have an arrow which is supposed to rotate in response to user input. This particular node JUST WON’T MOVE. I went back to the documentation, but I can’t find anything new to help…

[java]inputManager.addMapping(“aimTurnRight”, new KeyTrigger(keyInput.KEY_D));[/java]

[java]inputManager.addListener(this, “aimTurnRight”);[/java]

[java]public void onAnalog(String name, float value, float tpf) {
if(name.equals(“aimTurnLeft”) && rotate)
{
arrow.rotate(0f, 100*tpf, 0f);
}
}[/java]

Why won’t the node move?

2 Likes

To prevent stuff like that happening again, make it a class static or final string member variable, instead of hardcoding it in

1 Like

@pspeed , @wezrule , I’m sorry, that was a mistake, I cut the wrong piece of code. It is written “aimTurnRight” correctly. (Excuse me. :-/ )

[java]public void onAnalog(String name, float value, float tpf) {
if(name.equals(“aimTurnRight”) && rotate)
{
arrow.rotate(0f, -100*tpf, 0f);
}
}[/java]

But the node still won’t rotate.

Try breakpointing it. See if the method is called, see why the rotate doesn’t happen.

I promise you that rotating nodes does rotate nodes so it’s something you are doing…

@M-ASH said: @pspeed , @wezrule , I'm sorry, that was a mistake, I cut the wrong piece of code. It is written "aimTurnRight" correctly. (Excuse me. :-/ )

[java]public void onAnalog(String name, float value, float tpf) {
if(name.equals(“aimTurnRight”) && rotate)
{
arrow.rotate(0f, -100*tpf, 0f);
}
}[/java]

But the node still won’t rotate.

This is why we suggest learning Java before trying to write a Java game. These sorts of issues are really easy to track down if you have even the most basic Java debugging skills. As zarch indicates, either set a break point to see if onAnalog is called and step through what it’s doing or put some printlns around to validate assumptions and see what your bug is. Like, put a println at the beginning of onAnalag printing the name and the value of “rotate”, etc… then one inside the if.

Basically (assuming the method is even called) verify the incorrect assumptions that lead you believe that the if block executes.

And if none of the printlns show up then you can backtrack and figure out why your listener is not getting registered.