So i am working on a new project. Over here the player should be in the center of the camera.But also i want to make the camera follow the mouse a bit.This being said , i have this code:
override public function update():void
{
super.update();
cameraFollowTurgetAndPlayer();
}
public function cameraFollowTurgetAndPlayer():void
{
calculateingMouseDiff();
FP.camera.x = ((G.Px + 4) - FP.halfWidth) - mouseDiffX;
FP.camera.y = ((G.Py + 4) - FP.halfHeight) - mouseDiffY;
}
public function calculateingMouseDiff():void
{
//px,py - player coordinates
if (G.Px > G.Tx) {
mouseDiffX = (G.Px - Input.mouseX) / 10;
}
else {
mouseDiffX = (Input.mouseX - G.Px) / 10;
mouseDiffX = -mouseDiffX;
}
if (G.Py > G.Ty) {
mouseDiffY = (G.Py - Input.mouseY) / 10;
}
else {
mouseDiffY = (Input.mouseY - G.Py) / 10;
mouseDiffY = -mouseDiffY;
}
}
The problem is that when the player moves, mouseDiffX and mouseDiffy variables increase. And here is the part when i have no ideas left how to fix it. Do you guys have any? Thx.