Hi =) This will be my first post so yeah.
I have this helper class which makes the camera follows a certain entity. The entity has some leeway distance from the center of the screen before the camera mover class considers to follow it. It works just fine when the player moves horizontally. But when the movement is vertical, the camera starts doing weird things. The camera would shift its position vertically. What I mean is that the camera would teleport vertically on a up-down-up-down manner every frame(think vertical screen shake). This mostly happens when the entity is moving down the screen. I also noticed that if the player is somewhere in the middle of the world height, the camera would do the weird thing regardless of the players vertical velocity. My game is a platformer game. The weird thing doesn’t affect the camera along the x-axis.
Here is the relevant code for repositioning the camera along the y-axis:
// upper bounds
if (entity.y < FP.camera.y + halfCameraHeight - yThreshold)
{
FP.camera.y = (entity.y - halfCameraHeight + yThreshold);
}
// lower bounds
else if (entity.y + entity.height > FP.camera.y + halfCameraHeight + yThreshold)
{
FP.camera.y = entity.y + entity.height - halfCameraHeight - yThreshold;
}
Any ideas?