Controllers and controlling

I’m working on a little tower defense game.

Inside my enemy class I built a moveForward() method to have they march along the road as they get shot.

The method just read a list of vectors and moves the enemy 1 unit closer towards the next point each call. I then iterator over all the enemies in the game calling that method on each one every so often to generate a moving line of enemies. This loop is embedded in my simpleUpdate.

Everything’s good and works here.

When I decided that I wanted the enemies to have some spin, I added a spatial transformer to each enemy as I created it, and had them spin, adding it as their controllers and them as each transformers object. So 1 transformer to each enemy.

Once I implemented that they would spawn, stand in place and spin.

What is your question?

Why won’t my objects continue moving as they were beforehand?

Had created a method that I called to have them march forward, it worked.

I added a controller (spatial transformer) to spin them hoping that they two things would both happen, marching, spinning objects. But they only spin.

Any ideas?

We’d have to see the code of your controls to know whats wrong. Controls are called sequentially on updateLogicalState() so no reason why they shouldnt work both.

If I’m reading this right, wouldn’t moving forward and spinning just cause them to sit there making little loops of movement? If you’re attempting to make them move forward and rotate independently, you might consider using two nodes: One to have the straight line movement and the other attached below this one to handle spinning.

Movement Node (+movement control) - with child - Rotation Node (+spinning control) - with child - Your models?

Something like that perhaps? Shooting in the dark really without more details XD


Verbose Version

Codewise I had a method I created as part of a enemy class, the path variable is a vector array holding the vectors which the object follows. It was called moveForward and did this;

[java] public void moveForward(){

if( path.get( path.size() - 1 ).equals( this.getLocalTranslation() ) ){

this.dead = true; // Allows the gameloop to end the current wave correctly

this.looted = true; // Prevents the gameloop from crediting the player for the kill

this.survived = true; // Counts against the player






Vector3f dest = path.get(pathPos + 1); // Get the next destination

if( dest.equals(this.getLocalTranslation()) ){ // If we’re there already, get the next


dest = path.get(pathPos + 1);


Vector3f dir = dest.subtract(this.getLocalTranslation());

float x = this.getLocalTranslation().x + (dir.x > 0 ? .5f: dir.x == 0 ? 0:-.5f); // Moves us based on which way we need to go

float y = this.getLocalTranslation().y;

float z = this.getLocalTranslation().z + (dir.z > 0 ? .5f: dir.z == 0 ? 0:-.5f);

dir.x = x; //////////////////////////////////////////////////////////////////////////////////////////////////

dir.y = y; // IMPORTANT! - if you use this.setLocalTranslation( float, float, float) the path corrupts //

dir.z = z; // so you must construct the new vector to translate by! //


degrees += 45;

radians = degrees * FastMath.DEG_TO_RAD;

spin.fromAngleAxis( radians , new Vector3f(0, 1, 0) );




As you might see I added a spin into the function itself to workaround the issue earlier.

This is a decent solution but I’m still just wondering why adding a SpatialTransformer controller to this same object caused it to stay in place and spin according to the SpatialTransformer I declared (the same as the example on in the SpatialTransformer tutorial)?

Also I had a quick question about localtranslation; as you can see from the giant comment block in my method I had earlier by trying to use this.setLocalTranslation( float, float, float) to move the object but they wouldn’t move at all, when I changed it to this.setLocalTranslation(vector3f) it worked. The only difference in the actual class code of Spatial;

[java]public void setLocalTranslation(Vector3f localTranslation) {

this.localTranslation = localTranslation;



public void setLocalTranslation(float x, float y, float z) {

localTranslation.set(x, y, z);



is the usage of “this”. I don’t think I follow why that is different, or the exact utilization of the “this” keyword?

That’s a bit of a ramble so concise version;

  1. I had that above moveForward() method that I called in simpleUpdate every X millisecond to generate movement along a path variable.

    When I added a SpatialTransformer ( almost word for word from the tutorial, (djusting variable names etc) the objects stopped moving and just spawned and spun in place.
  2. getLocalTranslation has caused me a few grievances due to my lack of understanding; I have an example I think would illuminate the problem to me;

    I create the most basic simpleGame example, a grey box nothing else.

    I make another box and I setLocalTranslation it to 0,0,0 before I attach it. Should it be at the gamespace’s origin?

    I then attach it to the first grey box and setLocalTranslation it to 0,0,0. Should it now be at the same spot as the first grey box?


baad baaad baaaaaaaaad dog :stuck_out_tongue:

This wont work. Dont override the Spatials but create Controls for them and modify them with the available methods. If you restrain to that it will work.

Never override the base methods of a spatial, doing this kind of stuff requires you to know the update sequence in and out and you will definitely mess things up if you dont (even Momoko_Fan and me sometimes struggle here).

I didn’t override the Spatial?

I was just copying those two localtranslation methods for citation (those are the originals i have? I never overrode those??). that is the exact code from my Spatial.class file in the jme.jar from the JME_2_0_1_stable release. Is something amiss?

The moveForward method I displayed is part of a Critter class I created that extends Sphere, nothing overriden there right?

Oh, this is jME2… Ok, but still this one method is not a complete Control is it?

“complete Control”? dunno what you mean by that. The class isn’t a controller if that’s what you mean.

You said they are only spinning, not moving. So your spinning Control seems to be where the problem is.

Yes well the spinning controller is the SpatialTransformer directly taken from the tutorial. ( All I did was adapter the variable name where appropriate. I create a new SpatialTransformer for each object so that the implementation is identical to the tutorial.

So its just replacing,not advancing the values, you will have to extend the controller to make it do what you want.