georage Posted July 15, 2016 Share Posted July 15, 2016 (edited) Hello again friends! I am trying to smoothly slide a free camera along an X axis to keep up with a moving object (a hockey puck). I created this smoothMove function and expected it to work smoothly ... but the camera jitters at times if my smoothMove speed is over 0.3 or so. Not sure why. If I use a smoothMove speed that slow the camera cannot track the puck from one end of the ice to the other fast enough sometimes. Any ideas? Am I reinventing the wheel here? I can't find how to smooth out the follow of a free camera in the docs. function smoothMove(camera){ var puckPosX = puck.position.x; var camPosX = camera.position.x; //limit movement var xMax = 110; var xMin = -110; if(puckPosX > xMax) { puckPosX = xMax; } else if(puckPosX < xMin) { puckPosX = xMin; } //smooth move ... camera does not move fast enough! var smoothMove = 0.33; if(Math.abs(puckPosX-camPosX) >= smoothMove * 10){ if (camPosX < puckPosX){ puckPosX = camPosX + smoothMove; } if (camPosX > puckPosX){ puckPosX = camPosX - smoothMove; } //follow puck console.log("puckX="+puckPosX+" camX="+camPosX); camera.position.x = puckPosX; } } Edited July 15, 2016 by georage formatting Quote Link to comment Share on other sites More sharing options...
adam Posted July 15, 2016 Share Posted July 15, 2016 This PG might help: http://www.babylonjs-playground.com/#MQX8B#2 Use the arrow keys to move the sphere. Quote Link to comment Share on other sites More sharing options...
georage Posted July 15, 2016 Author Share Posted July 15, 2016 Thanks, that's some pretty smooth movement there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.