Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I discovered Copperlicht yesterday and thought the movement in the tutorials could be helped with a little easier WSAD rather than mouselook and modified the Javascript to allow friendlier movement. This Javascript is modified from the JS out of Tutorial2. Post size restrictions made me remove comments. Hope someone may find this useful. W / S Forward/Back A / D Turn Left / Right Replace the Javascript in tutorial2 to use it. Remove all ***'s before use [code] <script type="text/javascript"> <!-- var engine = startCopperLichtFromFile('3darea', 'copperlichtdata/index.ccbjs'); var cubeSceneNode = null; var rootSceneNode = null; var animator = null; var cam = null; var angle = 0; var deltaX = 1; var deltaY = 1; var twoPI = Math.PI * 2; var cam_x = 500; var cam_z = 0; engine.On***LoadingComplete = function() { var scene = engine.getScene(); if (scene) { cam = new CL3D.CameraSceneNode(); cam.Pos.X = cam_x; cam.Pos.Z = cam_z; scene.setRedrawMode(CL3D.Scene.REDRAW_EVERY_FRAME); animator = new CL3D.AnimatorCameraFPS(cam, engine); cam.addAnimator(animator); animator.lookAt(new CL3D.Vect3d(1000,0,0)); scene.getRootSceneNode().addChild(cam); scene.setActiveCamera(cam); rootSceneNode = scene.getRootSceneNode(); rootSceneNode.Pos.X = cam_x; rootSceneNode.Pos.Z = cam_z; cubeSceneNode = scene.getSceneNodeFromName('cubeMesh1'); scene.setRedrawMode(CL3D.Scene.REDRAW_EVERY_FRAME); var sphereSceneNode = scene.getSceneNodeFromName('sphereMesh1'); if (sphereSceneNode) sphereSceneNode.addAnimator(new CL3D.AnimatorRotation(new CL3D.Vect3d(0, 1.6, 0.8))); } } document.on***key***down = function(event) { = function(event) { var key = String.fromCharCode(event.keyCode); // when pressed 'L', move the cube scene node a bit up if (key == 'F' && cubeSceneNode) cubeSceneNode.Pos.Y += 5; // when pressed 'G', move the cube scene node a bit down if (key == 'G' && cubeSceneNode) cubeSceneNode.Pos.Y -= 5; if (key == 'W') { rootSceneNode.Pos.X = cam_x = cam_x - Math.cos(angle) * 3; rootSceneNode.Pos.Z = cam_z = cam_z - Math.sin(angle) * 3; } if (key == 'S') { rootSceneNode.Pos.X = cam_x = cam_x + Math.cos(angle) * 3; rootSceneNode.Pos.Z = cam_z = cam_z + Math.sin(angle) * 3; } if (key == 'D') { angle -= 0.1; deltaX = 3000 * Math.cos (angle); deltaY = 3000 * Math.sin (angle); animator.lookAt(new CL3D.Vect3d(deltaX*10000,0,deltaY*10000)); } if (key == 'A') { angle += 0.1; deltaX = 3000 * Math.cos (angle); deltaY = 3000 * Math.sin (angle); animator.lookAt(new CL3D.Vect3d(deltaX*10000,0,deltaY*10000)); } if(angle > twoPI)angle -= twoPI; if(angle < 0)angle += twoPI; //engine.handleKeyDown(event); }; --> </script> [/ |
||||
|
Thanks for posting! I guess I need to update the forum software, parts of your code have been removed obviously. |
||||
|
Eep Forum seems to remove keywords. I added *** in between keywords |
||||
|
I was working on this again today after downloading the CL latest update and modified CL itself to give me the keyboard movements I was looking for. I use a laptop almost 100% of the time for my development work so using "mouselook" doesn't work for me very well. In the function,
I removed,
and replaced it with
down below
leaving the final results to be set on the bottom by
I'll add a setter to simply apply this to a prototype later on rather than messing with copperlicht.js itself, but just wanted to share the results. Thanks for making CooperLicht, it's an excellent work. |
|