Hello!
I splitted um my Code which created a simple Scene and a moveable character.
Before i splitted it up to more classes (like player, or scene...) the collision worked fine.
But now I get the exception you see in the title :
Object3D.checkForCollisionEllipsoid(Unknown Source)
The whole exception says:
Exception in thread "main" java.lang.NullPointerException
at com.threed.jpct.Object3D.checkForCollisionEllipsoid(Unknown Source)
at WWWGame.Game.loop(Game.java:131)
at WWWGame.Game.start(Game.java:81)
at Start.init(Start.java:30)
at Start.main(Start.java:16)
So there must be a variable in line 131 which is null... but there isn't.
Thats the line:
moveRes = szene.getPlayer().getObject().checkForCollisionEllipsoid(moveRes,
ellipsoid, 8);
All variabled are defined and not null.
Any idea what the problem is?
lol, the 8) should be a 8 )^^
Maybe the same reason as in this thread: http://www.jpct.net/forum2/index.php/topic,2226.msg16428.html (http://www.jpct.net/forum2/index.php/topic,2226.msg16428.html)? (I.e. failed to add the object to the world). The next release will handle this case with a better error message.
I'm actually having the same problem though the object has been added to the world. I'm trying to add collision detection to the Ninja from the Bones demo, this function is called in the initialization bit:
private void addNinja() {
AnimatedGroup ninja = masterNinja.clone(AnimatedGroup.MESH_DONT_REUSE);
ninja.getRoot().translate(0,0,-20);
ninja.getRoot().setCollisionMode(Object3D.COLLISION_CHECK_SELF);
ninja.addToWorld(world);
ninjas.add(ninja);
}
And upon pressing a button I try to check for collisions before applying the translations
directionVector = new SimpleVector(0,0,2);
.....
directionVector = ninjas.get(0).getRoot().checkForCollisionEllipsoid(directionVector, ellipsoid, 2);
ninjas.get(0).getRoot().translate(directionVector);
But I keep getting a Null error for the checkForCollision line?
EDIT:
Raft just helped me out with this. For an AnimatedGroup the set and check need to be done on the Animated3D object, not on the Object3D. In the Ninja demo ninjas.get(0) returns the animated group, ninjas.get(0).get(0) returns the Animated3D object:
ninjas.get(0).get(0).setCollisionMode(Object3D.COLLISION_CHECK_SELF);
directionVector = ninjas.get(0).get(0).checkForCollisionEllipsoid(directionVector, ellipsoid, 1);