Problems with Chase Camera

hy monkeys :wink: i am tring to set Chase Camera in my game.

My application extends SimpleApplication where is already defined a camera (is name is cam); but i don’t want to use this cam,so

i created a new Camera.

When a create a camera i also create a ChaseCamera using camera that i have created.

but when i run application camera doesn’t display anything.

So i am gone to view code in Application class where is define cam camera and i have seen that there is a method called initCamera for initializa cam.

i copied this method in my application for initialized my new camera but doesn’t work.

anybody can help me?



[java]

//camera definition

Camera camera = new Camera(20,20);



initCamera(camera);



// i created a new node that chase camera follow

Node n = new Node();

CapsuleCollisionShape shape = new CapsuleCollisionShape(5f, 5f, 1);

CharacterControl c = new CharacterControl(shape,1f);

c.setPhysicsLocation(new Vector3f(3500,-90,3500));

n.setLocalTranslation(new Vector3f(3500,-90,3500));

n.addControl©;

rootNode.attachChild(n);

bulletAppState.getPhysicsSpace().add©;



ChaseCamera chaseCamera = new ChaseCamera(camera,n,inputManager);

//in this way chase camera is inside of capsulecollisionshape

chaseCamera.setDefaultDistance(0f);





//this is method that i copied by aplication class for init my new camera

private void initCamera(Camera cam){

cam = new Camera(settings.getWidth(), settings.getHeight());



cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);

cam.lookAt(new Vector3f(3493.4607f,-90.0f,3208.726f), Vector3f.UNIT_Y);



renderManager = new RenderManager(renderer);

//Remy - 09/14/2010 setted the timer in the renderManager

renderManager.setTimer(timer);

viewPort = renderManager.createMainView(“Default”, cam);

viewPort.setClearEnabled(true);



// Create a new cam for the gui

Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());

guiViewPort = renderManager.createPostView(“Gui Default”, guiCam);

guiViewPort.setClearEnabled(false);

}

[/java]

Just use the old cam and set flyCam.setEnabled(false) to turn off the existing control on it

Yeah the cam object is linked to the viewport, so if you create a new camera without viewport, nothing is rendered.



Use the cam object, create a ChaseCam from it and disable the flyCam like Normen said.



You can look at the TestChaseCam for an example

ok… in this way chase camera doesn’t move.

i definde chase camera in this way :

[java]

ChaseCamera chaseCamera = new ChaseCamera(cam,n,inputManager);

[/java]

where inptutManager derive from super class SimpleApplication.

i have to change inputMager with a new InputManager?



thanks a lot for quick support :wink:

you can’t even rotate with the cam pressing the mouse’s left button?

no :frowning:

where i can find TestChaseCam class that i want to view an example? :wink:

Create a new JmeTests project

ok now camera works.

for make it works i moved 2 lines of code that attach characterControl and my node n after chaseCamera definition.

is there possibility to move camera without pressing mouse button(like flyCam)?

:wink:

there is a flag you must set/unset:

chaseCam.setDragToRotate(false);

1 Like

ok thanks…all works…only a question…this camera rotate with lag. is normal? flyCam it was fast in rotate movement…

chaseCam.setSmoothing(false)



Try writing “chaseCam.” and then pressing ctrl-space and you will see all methods of that class with a description of what they do. Lots easier than asking for method names on the forum all the time :wink:

ok :wink: but this method doesn’t exist.

there is chaseCamera.setSmoothMotion(); but if i set this method to false chase cam doesn’t work…

try chaseCamera.setSmoothingSensitivity() or chaseCamera.setMotionSensitivity() or something like that, be sure to crank the value up :slight_smile:

ok i find problem and it was my code… :slight_smile: now i solved :wink: all works great :wink: now i read description of all methods of chaseCamera class for understand better this component. after i implement movement of camera :wink:

bisciasia said:
there is chaseCamera.setSmoothMotion(); but if i set this method to false chase cam doesn't work..

what do you mean doesn't work? you cant rotate? it does not follow the spatial. it does not go back in its trail? it crash with an exception?

oh ok did not see your last message nvm.