I am trying to write a simple method which will move a node (with spatials attached) from its current location to a new location smoothly over time. I thought that using a Motion Path and Motion Event would be best for this.
The code I have written is below - its fairly short… I really don’t see what I’m doing wrong, and the error it gives me doesn’t point to any part of my own code, so I am struggling to identify the problem. Do you think you’d be able to help?
Thank you for taking the time to have a look!
[java]
public void updatePeerLocationAndRotation(Vector3f newPos, Quaternion newRot)
{
MotionPath path = new MotionPath();
path.setCurveTension(0f);
path.addWayPoint(peerNode.getLocalTranslation());
path.addWayPoint(newPos);
Oct 10, 2014 2:16:11 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.jme3.math.Spline.initCatmullRomWayPoints(Spline.java:161)
at com.jme3.math.Spline.computeTotalLentgh(Spline.java:233)
at com.jme3.math.Spline.setCurveTension(Spline.java:320)
at com.jme3.cinematic.MotionPath.setCurveTension(MotionPath.java:341)
at mygame.PeerVehicle.updatePeerLocationAndRotation(PeerVehicle.java:144)
at mygame.GameClient.newPeer(GameClient.java:156)
at mygame.GameClient.handleData(GameClient.java:133)
at mygame.GameClient.receiveData(GameClient.java:108)
at mygame.Main.simpleUpdate(Main.java:170)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:242)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
If I put path.setCurveTension(0f); after I’ve set up the path, the error changes to:
Oct 10, 2014 5:58:52 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.jme3.math.Spline.interpolate(Spline.java:288)
at com.jme3.cinematic.MotionPath.interpolatePath(MotionPath.java:94)
at com.jme3.cinematic.events.MotionEvent.onUpdate(MotionEvent.java:199)
at com.jme3.cinematic.events.MotionEvent.internalUpdate(MotionEvent.java:181)
at com.jme3.cinematic.events.MotionEvent.update(MotionEvent.java:164)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
@Empire Phoenix
If I try adding 3 points (and do what pspeed suggested) it produces this error:
java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.jme3.math.Spline.interpolate(Spline.java:288)
at com.jme3.cinematic.MotionPath.interpolatePath(MotionPath.java:94)
at com.jme3.cinematic.events.MotionEvent.onUpdate(MotionEvent.java:199)
at com.jme3.cinematic.events.MotionEvent.internalUpdate(MotionEvent.java:181)
at com.jme3.cinematic.events.MotionEvent.update(MotionEvent.java:164)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
It says “Running on jMonkeyEngine 3.0.10” - When I check for updates it says “Your application is up to date”.
It might be worth mentioning that the class I am running the method above in, does not extend SimpleApplication.
The above method is in a class called PeerVehicle. Multiple PeerVehicles are created by my “Main” class which does extend SimpleApplication.
Could this be causing the problem? What do I need to do to fix it if so?
@EmpirePhoenix I have changed the order, as pspeed suggested the error I get when I change the order is:
Oct 10, 2014 5:58:52 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at com.jme3.math.Spline.interpolate(Spline.java:288)
at com.jme3.cinematic.MotionPath.interpolatePath(MotionPath.java:94)
at com.jme3.cinematic.events.MotionEvent.onUpdate(MotionEvent.java:199)
at com.jme3.cinematic.events.MotionEvent.internalUpdate(MotionEvent.java:181)
at com.jme3.cinematic.events.MotionEvent.update(MotionEvent.java:164)
at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
at com.jme3.scene.Node.updateLogicalState(Node.java:145)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.scene.Node.updateLogicalState(Node.java:152)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
…Unless I have misunderstood how I was supposed to change it:
[java]
…
MotionPath path = new MotionPath();
path.addWayPoint(peerNode.getLocalTranslation());
path.addWayPoint(newPos);
path.addWayPoint(newPos);
I think that’s because you have 2 waypoints that are the same next to each others. I think I fixed a bug like this. Could explain why you have the issue