Hi,
MotionPathListener’s onWayPointReach() method seems not to be always triggered, which is very anoying in my game…
Here’s the code:
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.MotionPathListener;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
public class Main extends SimpleApplication {
DirectionalLight sun;
MotionPath path;
public static SimpleApplication sapp;
public static void main(String[] args) {
Main app = new Main();
sapp = (SimpleApplication) app;
AppSettings settings = new AppSettings(true);
settings.setFrameRate(60);
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
sun = new DirectionalLight();
sun.setDirection(new Vector3f(0,-1,0).normalizeLocal());
sun.setColor(ColorRGBA.White);
sapp.getRootNode().addLight(sun);
sapp.getCamera().lookAtDirection(new Vector3f(0,-1,0), new Vector3f(0,0,-1));
sapp.getCamera().setLocation(new Vector3f(0f,30f,0f));
Box box = new Box(Vector3f.ZERO, 1f,1f,1f);
Material mat = new Material(sapp.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, ColorRGBA.Blue);
Spatial spatial = new Geometry(“test”, box);
spatial.setMaterial(mat);
sapp.getRootNode().attachChild(spatial);
path = new MotionPath();
float z = 10, x = 0, step = 1.5f;
path.addWayPoint(new Vector3f(x , -10 , z));
path.addWayPoint(new Vector3f(x , -10 , -z));
path.addWayPoint(new Vector3f(x , 0 , -z2/3));
path.addWayPoint(new Vector3f(x-step , 0 , -z1/3));
path.addWayPoint(new Vector3f(x+step , 0 , 0));
path.addWayPoint(new Vector3f(x-step , 0 , z1/3));
path.addWayPoint(new Vector3f(x+step , 0 , z2/3));
path.addWayPoint(new Vector3f(x-step , 0 , z));
path.addWayPoint(new Vector3f(x+step , 0 , z*4/3));
MotionTrack motionControl = new MotionTrack(spatial, path);
motionControl.setSpeed(2);
path.enableDebugShape(sapp.getAssetManager(), sapp.getRootNode());
// motionControl.setLoopMode(LoopMode.Loop);
motionControl.play();
}
@Override
public void simpleUpdate(float tpf) {
path.addListener( new MotionPathListener() {
public void onWayPointReach(MotionTrack control, int wayPointIndex) {
System.out.println("way point index: "+wayPointIndex);
}
});
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]
2 Likes
Thanks for the test case, apparently the problem only occur when frame rate is low.
I’m gonna look into it and keep you informed.
I committed a fix. Next nightly should fix your issue.
All right, it works. Thank you.