playMaker

Author Topic: Camera window in 2D game  (Read 2243 times)

markadet

  • Playmaker Newbie
  • *
  • Posts: 20
Camera window in 2D game
« on: June 07, 2016, 01:37:02 PM »
Hello!

I'm trying to make a script for a camera in a 2D platformer game. My goal is to have something like this:


or this:


That way the camera doesn't always follow the player, it follows only if he goes near the border of the screen.

In order to do this, I made 4 box collider 2D, children of the camera, surrounding the player object (up, down, left, right). If the player enters one of the box collider (right or left), it enters a state where it detects if the key to this direction is pressed. If yes, il locks the camera on player (setting it as child) ; when the input is released, it is detached.

This works, but only for left and right, and only if the move comes from input... So it doesn't really work. To fix this, I'm thinking of replacing the input detection by a detection of the player object's position every 0.1 when it's inside the box collider (for example), to see if it's moving (with a comparison of its current position with the position it had 0.1 sec before). Is this the good way? If not, how would you do something like this?

Thanks.
« Last Edit: June 07, 2016, 01:42:43 PM by markadet »