so i’m working on a motionpath to carry a character model in a set path for a game, however when i run the program the model stays on the starting point of the path and then starts rotating (?) on the point counter clockwise and then vanishes, i’m having difficulty fully understanding motionpath and how to attach a model can i get help?
[java]
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
setupKeys();
createLight();
createSky();
createTerrain();
createCharacter();
setupChaseCamera();
setupAnimationController();
setupFilter();
addEnemy();
setupEnemyAnimationController();
MotionPath path = new MotionPath();
path.addWayPoint(new Vector3f(-140, 15, 10));
path.addWayPoint(new Vector3f(-110, 15, 10));
path.addWayPoint(new Vector3f(-110, 15, 20));
path.addWayPoint(new Vector3f(-140, 15, 20));
path.setCycle(true);
path.setCurveTension(0.5f);
path.enableDebugShape(assetManager, rootNode);
motionControl = new MotionTrack(enemyMod1, path);
motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
motionControl.setInitialDuration(10f);
motionControl.setSpeed(1.5f);
motionControl.play();
}
private void setupEnemyAnimationController() {
enemyAnimControl = enemyMod1.getControl(AnimControl.class);
enemyAnimControl.addListener(this);
enemyAnimChannel = enemyAnimControl.createChannel();
enemyAnimChannel.setLoopMode(LoopMode.Loop);
}
private void addEnemy() {
CapsuleCollisionShape enemyCapsule = new CapsuleCollisionShape(3f, 4f);
enemy1 = new CharacterControl(enemyCapsule, 0.01f);
enemyMod1 = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
//model.setLocalScale(0.5f);
enemyMod1.addControl(enemy1);
rootNode.attachChild(enemyMod1);
getPhysicsSpace().add(enemy1);
}
[/java]
does anybody know the reason about this issue? I have the same problem. I found the problem is ‘‘CharactecControl’’.
Please if somebody know about that, help us!!
Thank you
well, I got the solution for this problem.
First, if you check the physics location of the CharacterControl, it does not change while the motionControl is playing.
Second, I did not find the reason, so if somebody know why, maybe can help us.
Third, the solution could be something like this:
path.addListener(new MotionPathListener() {
public void onWayPointReach(MotionTrack control, int wayPointIndex) {
if (path.getNbWayPoints() == wayPointIndex + 1) {
character_Disp.setPhysicsLocation(path.getWayPoint(wayPointIndex));
}
}
});
As you can see, in the listener for the path, when you get to the last ‘wayPoint’ you only need to updated the PhysicsLocation of the CharacterControl, and voila!!!
That is all.
… just disable the character if you don’t want to use it (which the use of motion paths implies) and replace it with a kinematic rigidbody with the same collision shape if you want it to push away other physics objects.