Hello, I’m trying put my new Camera code to project and got some problem: I’m getting error:
[java]warning CollisionDispatcher.needsCollision: static-static collision![/java]
Here’s camera class, I doesn’t create any other collisionshaped in other classes:
[java]
public class Camera3D extends Node implements ActionListener, PhysicsCollisionListener, PhysicsTickListener {
private Spatial scene;
private Node playerModel;
private ChaseCamera chaseCam;
public BulletAppState bulletAppStateCamera;
private RigidBodyControl landscape;
private CharacterControl player;
private Vector3f walkDirection = new Vector3f();
private boolean left = false, right = false, up = false, down = false;
private Vector3f camDir = new Vector3f();
private Vector3f camLeft = new Vector3f();
private Node cameraCollision;
private GhostControl camGhost;
private boolean isCollided = false;
private Vector3f directionCharVec = Vector3f.UNIT_Z.clone();
private boolean isAccelerate;
private float speedAccelerate, speedMove;
private GameState gs;
private Camera cam;
private Game game;
private InputManager inputManager;
public Camera3D(GameState gs, Node scene, Node playerModel, Camera cam, InputManager inputManager) {
this.gs = gs;
this.scene = scene;
this.playerModel = playerModel;
this.cam = cam;
this.inputManager = inputManager;
}
public void createBullet() {
bulletAppStateCamera = new BulletAppState();
}
public void initCamera() {
game = new Game();
Node rootNode = game.getRootNode();
for (Spatial xSp : playerModel.getChildren()) {
xSp.setLocalTranslation(xSp.getLocalTranslation().subtract(new Vector3f(0, 1, 0)));
}
CollisionShape sceneShape =
CollisionShapeFactory.createMeshShape((Node) scene);
landscape = new RigidBodyControl(sceneShape, 0);
scene.addControl(landscape);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(0, 10, 0));
playerModel.addControl(player);
speedAccelerate = 3.5f;
speedMove = 0.1f;
rootNode.attachChild(scene);
rootNode.attachChild(playerModel);
bulletAppStateCamera.getPhysicsSpace().add(landscape);
bulletAppStateCamera.getPhysicsSpace().add(player);
inputManager.setCursorVisible(false);
chaseCam = new ChaseCamera(cam, playerModel, inputManager);
chaseCam.setDragToRotate(false);
chaseCam.setLookAtOffset(new Vector3f(0, 1, 0));
chaseCam.setMinDistance(3);
chaseCam.setDownRotateOnCloseViewOnly(false);
chaseCam.setMinVerticalRotation(FastMath.DEG_TO_RAD * -50f);
chaseCam.setMaxVerticalRotation(FastMath.DEG_TO_RAD * 85f);
System.out.println(chaseCam.getMaxVerticalRotation() + "MAX");
System.out.println(chaseCam.getMinVerticalRotation() + "MIN");
camGhost = new GhostControl(new SphereCollisionShape(0f));
cameraCollision = new Node("CameraCollision");
cameraCollision.addControl(camGhost);
bulletAppStateCamera.getPhysicsSpace().add(camGhost);
rootNode.attachChild(cameraCollision);
bulletAppStateCamera.getPhysicsSpace().addCollisionListener(this);
bulletAppStateCamera.getPhysicsSpace().addTickListener(this);
}
public void setUpKeys() {
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("SpeedMove", new KeyTrigger(KeyInput.KEY_LSHIFT));
inputManager.addListener(this, "SpeedMove");
inputManager.addListener(this, "Left");
inputManager.addListener(this, "Right");
inputManager.addListener(this, "Up");
inputManager.addListener(this, "Down");
inputManager.addListener(this, "Jump");
}
public void onAction(String binding, boolean isPressed, float tpf) {
if (binding.equals("Left")) {
left = isPressed;
} else if (binding.equals("Right")) {
right = isPressed;
} else if (binding.equals("Up")) {
up = isPressed;
} else if (binding.equals("Down")) {
down = isPressed;
} else if (binding.equals("Jump")) {
if (isPressed) {
player.jump();
}
} else if (binding.equals("SpeedMove")) {
isAccelerate = isPressed;
}
}
public void updateCamera(float tpf) {
inputManager.setCursorVisible(false);
walkDirection.set(0, 0, 0);
Vector3f newDirection;
float angleToRotateCamera = 0;
if (left) {
walkDirection.addLocal(cam.getLeft());
} else if (right) {
walkDirection.addLocal(cam.getLeft().negate());
}
if (up) {
walkDirection.addLocal(cam.getDirection().clone().setY(0f)).normalizeLocal();
} else if (down) {
walkDirection.addLocal(cam.getDirection().clone().setY(0f).negateLocal()).normalizeLocal();
}
if (up || down | left || right) {
directionCharVec = walkDirection.clone();
}
player.setViewDirection(player.getViewDirection().clone().interpolate(directionCharVec, 0.3f));
if (isAccelerate) {
walkDirection.multLocal(speedMove * speedAccelerate);
} else {
walkDirection.multLocal(speedMove);
}
player.setWalkDirection(walkDirection);
Node rigNode = (Node) playerModel.getChild("rig");
for (Spatial sp : rigNode.getChildren()) {
AnimControl animCtrl = sp.getControl(AnimControl.class);
if (animCtrl.getNumChannels() == 0) {
animCtrl.createChannel();
}
AnimChannel channel = animCtrl.getChannel(0);
if (up || down || right || left) {
if (channel.getAnimationName() == null) {
channel.setAnim("rigAction", 1f);
channel.setLoopMode(LoopMode.Loop);
}
} else {
channel.reset(true);
}
}
if (isCollided) {
float setDist = chaseCam.getDistanceToTarget() - 5f;
if (setDist < chaseCam.getMinDistance()) {
setDist = chaseCam.getMinDistance() + 0.1f;
}
chaseCam.setDefaultDistance(setDist);
isCollided = false;
}
cameraCollision.setLocalTranslation(cam.getLocation());
}
public void collision(PhysicsCollisionEvent event) {
if ((event.getNodeA() != null && event.getNodeB() != null)) {
if ((event.getNodeA().equals(cameraCollision) || event.getNodeB().equals(cameraCollision))
&& (!event.getNodeA().equals(playerModel) || !event.getNodeB().equals(playerModel))) {
isCollided = true;
}
}
}
public void prePhysicsTick(PhysicsSpace space, float tpf) {
}
public void physicsTick(PhysicsSpace space, float tpf) {
List<PhysicsRayTestResult> results = bulletAppStateCamera.getPhysicsSpace().rayTest(cameraCollision.getLocalTranslation(), player.getPhysicsLocation().clone().addLocal(Vector3f.UNIT_Y));
if (results.size() > 0) {
for (PhysicsRayTestResult obj : results) {
Spatial theObj = (Spatial) obj.getCollisionObject().getUserObject();
if (!theObj.equals(playerModel) && !theObj.equals(cameraCollision)) {
isCollided = true;
}
}
}
}
public BulletAppState getBullet() {
return bulletAppStateCamera;
}
}[/java]