[SOLVED] Node not moving with MotionPath

Hello everyone,
I have started (as you may already have noticed ont the March screenshot thread) working on a locomotive for my game.
It should use a motionpath for the tracks. (The actual tracks are part of the scene)
This is the class:

package Entity.Vehicle;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;

/**
 *
 * @author Robbi Blechdose
 *
 */
//TODO: MP
//Also implement driving backwards with the locomotive?
public class EntityLocomotive extends EntityVehicleBase
{
    private MotionPath tracks;
    private MotionEvent trackControl;
    private boolean isPlaying = false;
    private int lengthSeconds;
    
    public EntityLocomotive() {}
    
    public void initialize(AssetManager assetManager, BulletAppState bulletAppState, Node rootNode, Vector3f pos, MotionPath tracks, int lengthSeconds)
    {
        this.tracks = tracks;
        init(assetManager, bulletAppState, rootNode, "Models/Locomotive/Locomotive_01.j3o", pos, 0, 0, "EntityLocomotive", false);
    }
    
    @Override
    public void ownInit(AssetManager assetManager, BulletAppState bulletAppState, Node rootNode, Vector3f pos)
    {
        super.ownInit(assetManager, bulletAppState, rootNode, pos);
        
        bulletAppState.getPhysicsSpace().remove(entityRigidControl);
        bulletAppState.getPhysicsSpace().remove(entityControl);
        entityNode.removeControl(entityRigidControl);
        entityNode.removeControl(entityControl);
        
        trackControl = new MotionEvent(entityNode, tracks);
        trackControl.setSpeed(1f);
        trackControl.setInitialDuration(lengthSeconds);
    }
    
    //TODO: Why is the vehicle not moving?
    @Override
    public void steer(int direction)
    {
        if(direction == EntityVehicleBase.STEER_FORWARD)
        {
            this.goForward();
        }
        else if(direction == EntityVehicleBase.STEER_STOP)
        {
            this.stop();
        }
    }
    
    public void goForward()
    {
        if(!isPlaying)
        {
            trackControl.play();
            this.isPlaying = true;
        }
    }
    
    public void stop()
    {
        if(isPlaying)
        {
            trackControl.pause();
            this.isPlaying = false;
        }
    }
}

The problem is that the locomotive doesn’t move when I call the methods.
[The superclass is not relevant here, it’s just a basic vehicle that is an interface for interaction, and it’s superclassing the super-simple entity. (Yes, I did write my own entity system)]
Can you help me?

Did you try to debug step by step to see what’s going on? It could be anything really… Where does entityNode comes from?

Also… as a side note, i’m not an expert in ES, but you should not mix your entities and your scene graph logic. These should be separate layers.
Also… an entity, should not be extended… because it’s will ever just be that… an entity. Its behaviour will depend on the components attached to it.

First of all, thanks for the answer.
The entityNode is from the super-superclass which is the basic node where the model is attached.
Thanks for the critic on my entity system, but I don’t really know what else I should do, and it’s working quite well right now.
I only use components for AI.

Also,
I have run some checks:
The methods are all getting called, the path is (for a test) correct, but the node just stays in its position.
What could be the problem?

Ok just a wild guess here: Maybe you have a System which holds your train/whatever in place? But as I have no clue what kind of ES you wrote/use nor the components/systems you have it’s hard to tell as @nehon it can be anything :smile:
And I as well would not mix it as you, depending of your components/systems you have, need to keep a possible position component up to date.

1 Like

Thank you for the answer,
but I don’t have anything like that in my ES. Also, the position is gotten right from the node. :smiley:
There is just an update method in every entity where stuff that needs to be executed every frame (e.g. AI calculations) can be put.

:chimpanzee_facepalm:
I can’t believe I actually did this mistake:
I forgot one line in initialize():

this.lengthSeconds = lengthSeconds;