ballphy = new RigidBodyControl(5f); //(ballphy is created)
ballphy.setCcdSweptSphereRadius(1f); //(here cones the error)
ballgeo.addControl(ballphy);
state.getPhysicsSpace().add(allphy); //(state is of BulletAppState)
/**
* Set the collision shape based on the controlled spatial and its
* descendents.
*/
protected void createCollisionShape() {
if (spatial == null) {
return;
}
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
if (mesh instanceof Sphere) {
collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
return;
} else if (mesh instanceof Box) {
collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
return;
}
}
if (mass > 0) {
collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
} else {
collisionShape = CollisionShapeFactory.createMeshShape(spatial);
}
}
its correct what you do, i just want mention that your situation is probably different because Mesh is not Sphere object so it cant determine how to generate it.
also it would be better if you provide this in constructor so this do not calculate it earlier itself.
Stacktrace:
{code}
вер. 06, 2019 1:11:55 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException: The native object does not exist.
at com.jme3.bullet.objects.PhysicsRigidBody.setCcdSweptSphereRadius(Native Method)
at com.jme3.bullet.objects.PhysicsRigidBody.setCcdSweptSphereRadius(PhysicsRigidBody.java:380)
at mygame.Main.shootCannonBall(Main.java:149)
at mygame.Main$1.onAction(Main.java:160)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:446)
at com.jme3.input.InputManager.processQueue(InputManager.java:864)
at com.jme3.input.InputManager.update(InputManager.java:914)
at com.jme3.app.LegacyApplication.update(LegacyApplication.java:724)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:227)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:748)
{code}