Jump to content

Operation smoothMove(camera)


georage
 Share

Recommended Posts

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 by georage
formatting
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...