Camera Node Problem

Thanks for ur replay jafella. If you will elaborate little more it will be really helpfull for me. I am using CharacterControl instead of RigidBodyControl. I also tried to add setPhysicsRotation but getting error. Here below is whole code. First execute below code and then Just uncomment this line “teaNode.addControl(phy);” and execute it again you will come know what’s the problem, Camera is getting stuck . It would be really great if u can fix the issue.

package test;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.*;
import com.jme3.material.Material;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.CameraControl.ControlDirection;
import com.jme3.scene.shape.Quad;
import com.jme3.system.AppSettings;

/**

  • A 3rd-person camera node follows a target (teapot). Follow the teapot with
  • WASD keys, rotate by dragging the mouse.
    */
    public class TestCameraNode extends SimpleApplication implements AnalogListener {

private Geometry teaGeom;
private Node teaNode;
CameraNode camNode;
protected CharacterControl phy;
boolean rotate = false;
Vector3f direction = new Vector3f();

public static void main(String[] args) {
TestCameraNode app = new TestCameraNode();
AppSettings s = new AppSettings(true);
s.setFrameRate(100);
app.setSettings(s);
app.start();
}

public void simpleInitApp() {
// load a teapot model
BulletAppState bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
phy = new CharacterControl(new CapsuleCollisionShape(0.5f, 1f, 1), .01f);
phy.setPhysicsLocation(new Vector3f(0, 10, 0));
phy.setGravity(0);
teaGeom = (Geometry) assetManager.loadModel(“Models/Teapot/Teapot.obj”);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);
teaGeom.setMaterial(mat);
//create a node to attach the geometry and the camera node
teaNode = new Node(“teaNode”);
teaNode.attachChild(teaGeom);
//teaNode.addControl(phy);
rootNode.attachChild(teaNode);
bulletAppState.getPhysicsSpace().add(phy);
// create a floor
mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));
Geometry ground = new Geometry(“ground”, new Quad(50, 50));
ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
ground.setLocalTranslation(-25, -1, 25);
ground.setMaterial(mat);
rootNode.attachChild(ground);

//creating the camera Node
camNode = new CameraNode("CamNode", cam);
//Setting the direction to Spatial to camera, this means the camera will copy the movements of the Node
camNode.setControlDir(ControlDirection.SpatialToCamera);
//attaching the camNode to the teaNode
teaNode.attachChild(camNode);
//setting the local translation of the cam node to move it away from the teanNode a bit
camNode.setLocalTranslation(new Vector3f(-10, 0, 0));
//setting the camNode to look at the teaNode
camNode.lookAt(teaNode.getLocalTranslation(), Vector3f.UNIT_Y);

//disable the default 1st-person flyCam (don't forget this!!)
flyCam.setEnabled(false);

registerInput();

}

public void registerInput() {
inputManager.addMapping(“rotateRight”, new MouseAxisTrigger(MouseInput.AXIS_X, true));
inputManager.addMapping(“rotateLeft”, new MouseAxisTrigger(MouseInput.AXIS_X, false));
inputManager.addListener(this, “rotateRight”, “rotateLeft”);
}

public void onAnalog(String name, float value, float tpf) {
//computing the normalized direction of the cam to move the teaNode
if (name.equals(“rotateRight”)) {
teaNode.rotate(0, 5 * tpf, 0);
}
if (name.equals(“rotateLeft”)) {
teaNode.rotate(0, -5 * tpf, 0);
}

}
}