Hello,
I have 3 physical objects in my scene:
- A player character (the blue “blobby”) which i made kinematic. It has a collision shape made of one sphere on top of another.
- A white ball which i copied from the Hello Physics tutorial.
- A floor (2DPlane)
The the (kinematic) player character .move()s in direction of the mouse (red sphere, aligned to the floor). So the vector from the player character towards the mouse (multiplied by sth.) is the actual movement of the player character (mouse far = more speed).
Now the issue I have:
When the player doesnt move, everything is great:
But when the player moves, the collision shape moves a bit slower and doesn’t catch up until the player gets slower or stops. When I use the player character to accelerate the ball the same issue appears on the ball.
Is this the tribute for using kinematic RigidBodyControls? What could I else use? With the CharacterControl my character rolls over the field and BetterCharacterControl isn’t applicable because theres no way to use my own collision shape.
Or am I doing something wrong? Here is the code (stripped away mouse movement, camera and materials):
[java]
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, -9.81f));
short width = 30;
short height = 50;
// Floor Creation
Quad q = new Quad(height, width);
Geometry geom = new Geometry("Field", q);
geom.setMaterial(grassMat);
geom.move(-height/2f, -width/2f, 0);
PlaneCollisionShape floorCS = new PlaneCollisionShape(new Plane(Vector3f.UNIT_Z, 0f));
geom.addControl(new RigidBodyControl(floorCS, 0f));
bulletAppState.getPhysicsSpace().add(geom);
rootNode.attachChild(geom);
// Football Creation
Geometry ball_geo = new Geometry("Football", new Sphere(16, 16, 0.3f));
ball_geo.setMaterial(ballMat);
rootNode.attachChild(ball_geo);
ball_geo.setLocalTranslation(cam.getLocation());
RigidBodyControl ball_phy = new RigidBodyControl(1f);
ball_geo.addControl(ball_phy);
bulletAppState.getPhysicsSpace().add(ball_phy);
ball_phy.setLinearVelocity(cam.getDirection().mult(25));
Node playerNode = new Node("Player");
playerNode.addControl(new BlobbyMoveControl());
CompoundCollisionShape playerCS = new CompoundCollisionShape();
playerCS.addChildShape(new SphereCollisionShape(0.49f), new Vector3f(0, 0, 0.491f));
playerCS.addChildShape(new SphereCollisionShape(0.356f), new Vector3f(0, 0, 1.18195f));
playerNode.addControl(new RigidBodyControl(playerCS, 5f));
playerNode.getControl(RigidBodyControl.class).setKinematic(true);
rootNode.attachChild(playerNode);
bulletAppState.getPhysicsSpace().add(playerNode);
Spatial playerGeo = assetManager.loadModel("Models/blobby.j3o");
playerGeo.setName("PlayerGeometry");
playerGeo.setMaterial(playerMat);
playerGeo.rotate(FastMath.HALF_PI, 0, FastMath.PI);
playerGeo.move(0, 1, 0);
playerNode.attachChild(playerGeo);
// Mouse
Sphere b = new Sphere(16, 16, 0.25f);
Geometry g = new Geometry("MouseBox", b);
g.setMaterial(mouseMat);
playerNode.attachChild(g);
}
// the BlobbyMoveControl:
public class BlobbyMoveControl extends AbstractControl {
@Override
protected void controlUpdate(float tpf) {
Vector3f movement = ((Node)spatial).getChild(“MouseBox”).getLocalTranslation().mult(1.2f*tpf);
spatial.move(movement);
}
//…
[/java]