frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

Help with 2-player camera

Here's the example > http://flowlab.io/game/view/1111368
I'm trying to make a camera that is centered between the two players by using this strategy:
A block always extracts the two player's x and y positions and averages them. Then it puts them in a camera. But for some reason, the camera isn't moving at all. What am I doing wrong?

Comments

  • edited February 20
    Hey @Biscuit Butter - I'm actually not sure why this isn't working, it looks like your logic is completely correct. I've made a ticket in Trello to investigate this issue here: https://trello.com/c/QCbQigPs/63-camera-manual-position-isnt-working-as-expected.

    In the mean time, you can make it work like this:

    Instead of sending the averages output to the camera x/y, send it to a position block so the entire camera object moves. Disable the solid checkbox in the Camera's physics properties (so the players cannot collide with it), and set the Camera objects's alpha to 0 (so it's invisible). Now the camera will behave the way you want.

    Thanks for reporting this.
  • Hey @Biscuit Butter - I finally got a chance to take a look at this in depth, and I don't believe that it is a bug after all. It looks like there are two issues:

    1) "AutoScroll X" is enabled on the camera, which means that the camera's x position will auto-locate, no matter what you send to the inputs. Turn off Auto Scroll X and the camera will start aligning correctly.

    2) The camera coordinates refer to the top left of the visible area, not the center. This means that your calculations will place the left edge of the camera between the two players. To center the camera, you'll want to subtract half the screen size in your Expression, like this:
    ((A+B)/2)-320. The screen is 20 tiles wide so (20*32)/2 = 320


    I've tweaked the Camera section in the Behavior Handbook to try and clarify this: https://flowlab.io/behavior_handbook/#components-camera
  • Thanks so much @grazer !
Sign In or Register to comment.

flowlab.io

| make games in your browser
@ 2017 Flowlab.io, All rights reserved.

Contact us

Get In Touch