   Camera logic for a 2D Side Scroller
  Hi! I am making a 2d side scroller. I want my camera to follow the player wherever he goes. But I do not want my player to be always in the center because it makes the user dizzy.I want my camera to behave like the camera of New Super Mario in Nintendo DS. When Mario begins to move right, the camera wont move until it hits the threshold (about a third of the screen). Then, the camera moves faster than the player so that the screen will be bias on the player's direction. Then both their velocity will be the same. When the player stops or decelerates, the camera also stops.Using the code below, the camera will always follow the player. I am using this right now but I want to change this to a better user-friendly cameraupdate(long frameTime) {    camera.setX(player.getX());    camera.setY(player.getY());}I do not want the camera to be dependent on the player's position. Instead, I want my camera to have its own velocity. It should only move itself only if the player is beginning to move away from the camera. The camera should have a threshold on when will it move. Also, I want the camera to be bias on where the player is facing. For example the player is running in the left direction, then the camera position should be less than the player's position so that the player can see a larger screen to the left. How do I do that? Here is a pseudo code.update(long frameTime) {    if (player is moving) {   if (player is moving left) {  camera accelerate to left   } else {  camera accelerate to right   }   //same logic for movement up and down    } else {   decelerate until it stops    }}The problem for this code is that it does not have a threshold. How do I put the logic for the threshold?I hope I explained my problem well. Feel free to ask me for clarifications.Thanks!   
  What about: if(player is moving left AND abs(camera.acceleration) < threshold)   ;  I assign a camera velocity based upon distance to tracked object.   The greater the distance, the faster the camera moves to catch up.camVelocity = (targetX-camX) *VELOCITY_FACTORYou might want to set your velocity factor to 1.0 at first, then adjust as necessary for the proper cam feel.For smoothness, I find acceleration/deceleration to work much better than a distance threshold.  So, I don't use a distance threshold at all.   If the player moves even slightly, I make the cam respond.However, if you want to use a threshold, its easy to do.  Just examine the same distance used when calculating camVelocity, and zero out camVelocity if the distance is under your assigned threshold.Example:distance = targetX -camXif (abs(distance) < MIN_DISTANCE) then  camVelocity = 0else  camVelocity = distance *VELOCITY_FACTORendif*** EDIT ***I just re-read your post and I see you were asking about having the camera lead the player as they run either direction.  I'm not an expert, but I'm happy to share my thoughts =)If you used something like:CamX = PlayerX +(PlayerDirection *CAM_DISTANCE)where PlayerDirection could either be +1 or -1....it would very jerky, but I think that's the basic function.  It needs to be enhanced to include acceleration/deceleration over time.CamX = PlayerX +(PlayerDirection *CAM_DISTANCE *t)would be a bit better, where t=elapsed timeAcceleration/Deceleration can be implemented as interpolation over time between CurrentVelocity and TargetVelocity.   It's not horribly difficult, but there are devils lurking in the details.  It requires a proper Frame Delta for one thing, which is part of a decent game loop.  Plus you'll need a custom data structure to store the various elements necessary to make the ongoing calculations.[Edited by - Whatz on March 25, 2010 5:42:45 PM];  Hi! Thanks for the reply. I will try your implementation and update you when I'm done.By the way, I noticed in New Super Mario in Nintendo DS that a slight movement from the player also moves the camera slightly (I think there are no thresholds). I think that the logic of the camera was to always bias the area where the player is facing. If that is the case, I won't be implementing the threshold.Thanks!   ;  Hey, does anyone know how to make the camera move in DarkBASIC Pro? I'm really stuck.Thanks in advance. =)   