This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by Manuel

Hi, i´m making a game with a character that is moving in the scene horizontally, i want that the screen follow this character like a camera, i already do that but what i really want is slow tracking, ie, having a small delay before the camera reaches the character, could you give me any idea to do this.


1 decade ago by stahlmanDesign

In the main.js update function this is the code that keeps the camera centred on the player:

// screen follows the player
			var player = this.getEntitiesByType(EntityPlayer)[0];
			if (player) {
				this.screen.x = player.pos.x - ig.system.width / 2;
				this.screen.y = player.pos.y - ig.system.height / 2;

Instead of having this.screen.x = the player.pos.x you'd have to figure in some kind of drag or friction. For example have it almost equal the player.pos, but then for the last 200 pixels or so, have it slowly approach the player.pos.

The easiest way would be to create an invisible entity that collides with NONE. It will always attempt to go to the centre of player. Use distanceTo(player) to determine that if EntityCameraDrag is within 200 pixels, then have it slow down its approach. Then instead of having the camera centre on player, have it centre on cameraDrag entity.
Page 1 of 1
« first « previous next › last »