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?