πŸŽ₯ Camera Follow Player

What is it?

The camera system in GameCrom allows the camera to automatically follow the player in order to keep them visible on screen during gameplay. This behavior is controlled through the cameraFollow property, along with several parameters that define how and when the camera moves.

πŸ“– Main parameters

βœ… Basic behavior

- If cameraFollow is set to false, the camera remains fixed.

- If cameraFollow is set to true, the camera will automatically move to keep the player within the visible area, respecting the defined margin and smoothing.

🧭 Follow axes

Using the cameraFollowAxis property, you can decide on which axes the camera should follow the player.

The axis that is not followed will remain fixed, even if the player moves in that direction.

🎯 Using custom players

By default, the camera system automatically follows any object of type player, top_down_player, flying_player, or point_click_player.

If you are using a player created through a custom script, you can manually tell the camera which object it should follow. To do this, add the following line in the Start event of the object script:

function Start(obj) {
  cameraFollowTarget = obj;
}

This assigns the current object as the camera target. Important: there must be no object of type player in the scene, as the engine’s automatic system has priority and will override this manual assignment.

🎬 Example without smoothing

{
  "cameraFollow": true,
  "cameraFollowAxis": "both",
  "cameraSmooth": 0,
  "cameraMargin": 50
}

πŸ‘‰ The camera will follow the player instantly when crossing the 50-pixel margin.

🎬 Example with smoothing

{
  "cameraFollow": true,
  "cameraFollowAxis": "both",
  "cameraSmooth": 5,
  "cameraMargin": 80
}

πŸ‘‰ The camera will move smoothly toward the player, keeping an 80-pixel margin.

🎬 Example: horizontal-only camera

{
  "cameraFollow": true,
  "cameraFollowAxis": "x",
  "cameraSmooth": 4,
  "cameraMargin": 60
}

πŸ‘‰ The camera will follow the player only horizontally, keeping the vertical position fixed.

🎬 Example: vertical-only camera

{
  "cameraFollow": true,
  "cameraFollowAxis": "y",
  "cameraSmooth": 6,
  "cameraMargin": 40
}

πŸ‘‰ The camera will follow the player only vertically.

πŸ“Œ Notes

- cameraSmooth = 0 results in a hard camera with no interpolation.
- Higher cameraSmooth values create slower, smoother movement.
- cameraMargin prevents constant micro-adjustments and jitter.
- cameraFollowAxis allows classic camera behaviors without extra scripts.
- cameraFollowTarget can point to any game object, as long as there is no active player in the scene.
- The system is compatible with camera bounds to avoid showing empty areas of the map.