I was testing my abilities in jMonkey when I tried to modfy the HelloPhysics exemple, so I tried to switch the cannonball:
[java]
public void makeCannonBall() {
/** Create a cannon ball geometry and attach to scene graph. /
Spatial ball_spa = defaultBall.clone();
ball_spa.setLocalScale(0.5f);
rootNode.attachChild(ball_spa);
/* Position the cannon ball and activate shadows /
ball_spa.setLocalTranslation(cam.getLocation());
ball_spa.setShadowMode(ShadowMode.CastAndReceive);
/* Make the ball physcial with a mass > 0.0f /
ball_phy = new RigidBodyControl(2f);
/* Add physical ball to physics space. /
ball_spa.addControl(ball_phy);
ball_phy.attachDebugShape(floor_mat);
bulletAppState.getPhysicsSpace().add(ball_phy);
/* Accelerate the physcial ball to shoot it. */
ball_phy.setLinearVelocity(cam.getDirection().mult(15f));
}
[/java]
defaultBall is a Spatial initied in simpleInitApp
[java] defaultBall = assetManager.loadModel(“Models/esfera/Sphere.mesh.xml”);[/java]
So, how you can see, in “ball_phy.attachDebugShape(floor_mat);” I took the prove, the ball_phy is launched in time and from position very differents.
So what?
Sorry, I “forget” the problem -.-
bad english
Would you believe it.
Ok, my english is weak to explain that, I will update a video and post it here.
Slow internet(Brazil), in 135min I post it here…
I guess the thing is that your spatial is not a Geometry with a mesh of type Sphere.
Here is: youtube video (I put a small video but have all the informations…)
The first ball is the Spatial and the second is the RigidBodyControl(I launched only one time).
I changed the method a little basing on HelloCollision exemple and here is:
[java]
public void makeCannonBall() {
/** Create a cannon ball geometry and attach to scene graph. /
Spatial ball_spa = defaultBall.clone();
ball_spa.setLocalScale(0.5f);
rootNode.attachChild(ball_spa);
/* Position the cannon ball and activate shadows /
ball_spa.setLocalTranslation(cam.getLocation());
ball_spa.setShadowMode(ShadowMode.CastAndReceive);
CollisionShape ballShape =
CollisionShapeFactory.createMeshShape((Node) ball_spa);
/* Make the ball physcial with a mass > 0.0f /
ball_phy = new RigidBodyControl(ballShape, 2f);
/* Add physical ball to physics space. /
ball_spa.addControl(ball_phy);
ball_phy.attachDebugShape(floor_mat);
bulletAppState.getPhysicsSpace().add(ball_phy);
/* Accelerate the physcial ball to shoot it. */
ball_phy.setLinearVelocity(cam.getDirection().mult(15f));
}
[/java]
It doesn’t afected anything.
A mesh shape cannot be moved, use createDynamicMeshShape to create a movable hull shape. But since this is a sphere I suggest using a SphereCollisionShape,
So, all ok if the sphere was not created in jMonkey (was in blender)? I can use SphereCollisionShape?
My hero!!
The code worked that way:
[java]
public void makeCannonBall() {
/** Create a cannon ball geometry and attach to scene graph. /
Spatial ball_spa = defaultBall.clone();
rootNode.attachChild(ball_spa);
/* Position the cannon ball and activate shadows /
ball_spa.setLocalTranslation(cam.getLocation());
ball_spa.setShadowMode(ShadowMode.CastAndReceive);
SphereCollisionShape ballShape = new SphereCollisionShape(0.5f);
/* Make the ball physcial with a mass > 0.0f /
RigidBodyControl ball_phy = new RigidBodyControl(ballShape, 2f);
/* Add physical ball to physics space. /
ball_spa.addControl(ball_phy);
ball_phy.attachDebugShape(floor_mat);
bulletAppState.getPhysicsSpace().add(ball_phy);
/* Accelerate the physcial ball to shoot it. */
ball_phy.setLinearVelocity(cam.getDirection().mult(15f));
}
[/java]