Camera Zoom and Move

Hello EveryOne

Please help me!

I want to zoom and move camera same iStunt2 game, but movement and zoom can not be smooth as iStunt.
I use setScale and setPosition:

Move camera on update function:
offsetx = 0.05;
offsety = 0.05;
b2Vec2 position = frame~~>GetPosition;
CCPoint myPosition = getPosition;
myPosition.x = position.x * PTM_RATIO;
myPosition.y = position.y * PTM_RATIO;
float xnext = this~~>getScale;
float offx = xnext~~ this->getPositionX;
offx
= offsetx;
xnext = this~~>getPositionX()+offx;

float ynext = (myPosition.y + screensize.height/ 2.0f)**this>getScale;
float offy = ynext~~ this->getPositionY;
offy**= offsety;
ynext = this~~>getPositionY()+offy;

this~~>setPosition;
and zoom:
float z = this~~>getScale() - 0.002;
if(z <= 0.3) z = 0.3;
this->setScale(z);

Zoom is OK, Move is OK but zoom + move is bad.

if im not mistaken, you are saying the camera is bad because it sticks to the target too hard, you will like to smooth it out right?

in this case, you can try lerp : http://en.wikipedia.org/wiki/Linear_interpolation

which in psuedo code is like this

setPosition((targetPosition - currentCameraPosition)*deltaTime+currentCameraPosition)

1 Like