Have probs rotating airplane following motionpath forinstance while doing a cuban eight. aerobatics.
How to stop spatial from flipping over at wrong moments?
got something like this:
final MotionPath motionPath = new MotionPath();
motionPath.addWayPoint(new Vector3f(-40, -10, z));
motionPath.addWayPoint(new Vector3f(-10, -10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 4) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 4) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 5) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 5) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 6) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 6) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 7) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 7) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 0) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 0) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 1) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 1) * 10, z));
motionPath.addWayPoint(new Vector3f(0, 0, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 3) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 3) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 4) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 4) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 5) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 5) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 6) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 6) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 7) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 7) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 0) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 0) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(FastMath.QUARTER_PI * 1) * 10 - 10, FastMath.cos(FastMath.QUARTER_PI * 1) * 10, z));
motionPath.addWayPoint(new Vector3f(0, 0, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 3) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 3) * 10, z));
motionPath.addWayPoint(new Vector3f(FastMath.sin(-FastMath.QUARTER_PI * 4) * 10 + 10, FastMath.cos(-FastMath.QUARTER_PI * 4) * 10, z));
motionPath.addWayPoint(new Vector3f(20, -10, z));
motionPath.addWayPoint(new Vector3f(40, -10, z));
motionPath.setCycle(false);
motionPath.setCurveTension(0.5f);
motionPath.enableDebugShape(assetManager, rootNode);
motionPath.disableDebugShape();
MotionEvent motionEvent = new MotionEvent(spatial, motionPath);
motionEvent.setInitialDuration(15f);
motionEvent.setSpeed(1.1f);
motionEvent.setLoopMode(LoopMode.Loop);
motionEvent.setDirectionType(MotionEvent.Direction.PathAndRotation);
motionEvent.setRotation(new Quaternion().fromAngleNormalAxis(0, Vector3f.ZERO));
motionEvent.play();
motionPath.addListener(new MotionPathListener() {
public void onWayPointReach(MotionEvent motionControl, int wayPointIndex) {
if (wayPointIndex == 2) {
channel.setAnim("level2up");
channel.setLoopMode(LoopMode.DontLoop);
// motionControl.getSpatial().rotate(0,0,1f);
}
if (wayPointIndex == 7) {
channel.reset(true);
}
if (wayPointIndex == 8) {
channel.setAnim("level2leftroll");
channel.setLoopMode(LoopMode.DontLoop);
// airPlane.rotate(0,0,FastMath.HALF_PI);
}
if (wayPointIndex == 9) {
channel.reset(true);
channel.setAnim("level2up");
channel.setLoopMode(LoopMode.DontLoop);
}
if (wayPointIndex == 15) {
channel.reset(true);;
}
if (wayPointIndex == 16) {
channel.setAnim("level2leftroll");
channel.setLoopMode(LoopMode.DontLoop);
}
if (wayPointIndex == 17) {
channel.reset(true);
channel.setAnim("level2up");
channel.setLoopMode(LoopMode.DontLoop);
}
if (wayPointIndex == 18) {
channel.reset(true);;
}
}
});
///////////////////////////////////////////////////////////////////////////
Cant Control rotation of spatial correctly.
Would love to learn to fly…