# MotionPath Airplane Aerobatics?

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(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(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(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.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();

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…

It’s really hard to say what’s wrong. could you shot a video of the issue?

What’s wrong is most likely me not using the MotionPath system correctly.

When airPlane reaches a waypoint like coming from the left on lower side of an O and reaching the middle right side of the O it flips over 180 degrees around the local z axcis automatically.
I am trying to have it almost around the Whole O and then controlled flip it around (180 degrees on the z)just above hte middel of the O on the left side again so that it flies inverse thru most of the O.

I dont seem to get motionControl.getSpatial().rotate(0,0,FastMath.PI); (or similar) to work in the listener.
MIght be I should use somthing other than MotionEvent.Direction.PathAndRotation.

Hhe, did you find solution?

No,
I am afraid I just settled for a path in the x z plane avoiding the plane to flip over or do a loop or something
I afraid I have not had the time to look deeper into it….

Many Regards
Harald

Sendt: 8. juni 2015 16:29
Til: Harald Gundersen
Emne: {Disarmed} [jMonkeyEngine Hub] [Troubleshooting/General Help] MotionPath Airplane Aerobatics?

Hhe, did you find solution?