Hi
I use a scene (from copperCube examples) with a 3rd-person camera.
Now I want to change the camera from 3rd to 1st camera while playing by pressing the 'G' key.
I've create a new camera with the collection detection (from tutorial).
There are two problems:
1. When I activate the 1st person camera, the person model still moves.
2. The active 1st-person camera does not move correctly. It stucks and has no gravity ... very buggy
My code is simple:
var engine = startCopperLichtFromFile('3darea', 'copperlichtdata/szene.ccbjs'); var camera3rd = null; var camera1st = null; var scene = null;
// this is called when loading the 3d scene has finished // for some reason in the forum I cannot use the text "O n L o a d ingComplete" engine.ingComplete = function() { scene = engine.getScene();
if (scene) { // find the cube scene node camera3rd = scene.getActiveCamera(); camera1st = new CL3D.CameraSceneNode(); scene.getRootSceneNode().addChild(camera1st);
var animatorFps = new CL3D.AnimatorCameraFPS(camera1st, engine); animatorFps.setLookByMouseDown(false); camera1st.addAnimator(animatorFps);
// add the collision response animator to collide against walls var colanimator = new CL3D.AnimatorCollisionResponse( new CL3D.Vect3d(10,20,10), // size of the player ellipsoid new CL3D.Vect3d(0,-10,0), // gravity direction new CL3D.Vect3d(0,20,0), // position of the eye in the ellipsoid scene.getCollisionGeometry()); camera1st.addAnimator(colanimator);
// also, force the 3d engine to update the scene every frame scene.setRedrawMode(CL3D.Scene.REDRAW_EVERY_FRAME); } } // for some reason in the forum I cannot use the text "o n k e y d o w n" document. = function(event) { var key = String.fromCharCode(event.keyCode); if (key == 'G') { camera1st.Pos = camera3rd.Pos.clone(); scene.setActiveCamera(camera1st); } engine.handleKeyDown(event); };
What's wrong?
|