Scrolling following character as soon as he walks

  • #1, by chrisMonday, 03. April 2017, 12:52 7 years ago
    Hi,
    I'm totally new to Visionaire and can't figure out how to set the camera scrolling in a large background to follow my character as soon as he moves.

    In the current state of my test game, when the character moves, the scrolling starts to follow him when he reaches some point near the edges of the screen.

    But I'd want the scrolling to start as soon as he starts moving. In that case, there would always be scrolling happening when the character walks.

    I tried to add the action "Center scene on character permanently" to my scene "at begining of scene", but it doesn't seem to do anything.

    How can I do ?
    Thanks !

    Newbie

    3 Posts


  • #2, by afrlmeMonday, 03. April 2017, 13:38 7 years ago
    A'llo,

    Center scene on character (permanently) is the default behaviour of the Visonaire Studio engine. It doesn't actually mean that the camera is centered on the character as that wouldn't be possible in all cases; like when the scene can't be scrolled any further on the x or y-axis. What it actually does is check listen out for when the character enters into an invisible bounding box & then scrolls the camera to center on the character or at least as far vertically or horizontally as it can go. You can actually adjust the vertical & horizontal bounding box distance quite easily with Lua script so that the camera is always centered on the character except when the scene can no longer scroll. Here's what you do...

    1. in game properties under game tab (cog icon), click on the lightning symbol next to at begin start following action to open up the box that lets you add some actions to execute on game launch.

    2. inside of this create an execute a script action part & add this code to it...
    game.GameHorizontalScrollDistance = (game.WindowResolution.x / 2) -- 50% resolution width
    game.GameVerticalScrollDistance = (game.WindowResolution.y / 2) -- 50% resolution height


    & that should do the trick for you. If you only want to affect camera on x or y axis then --comment out or delete whichever line you don't need. X = horizontal, Y = vertical.

    Imperator

    7278 Posts

  • #3, by chrisMonday, 03. April 2017, 14:19 7 years ago
    Thanks, that was fast!
    It's working very well and I understand I can tweak it a little bit changing the value.
    But I have a question with the value you set: With that, the scrolling follows the character and stops with him immediatly when going to the right.
    When going to the left, the scrolling doesn't stop immediatly with him, but goes a few pixel forward (on the left) and comes back to the character. It's a strange effect...

    Do you know where it might come from ?

    Newbie

    3 Posts

  • #4, by afrlmeMonday, 03. April 2017, 14:39 7 years ago
    No sorry. It's not something I bother doing. I prefer to let the character walk into the bounding boxes. Instead of having it centered exactly on the character you could adjust the width / height of the bounding boxes instead so that it's not exactly on the character...

    Actually wait... just thought of something... maybe it's because the values are the same & are causing conflict.

    Try...
    game.GameHorizontalScrollDistance = (game.WindowResolution.x / 2) - 10
    game.GameVerticalScrollDistance = (game.WindowResolution.y / 2) - 10

    It's not quite centered on the screen now. 10px offset now.

    Alternatively you could try using the openGL shader toolkit & the shaderFollowCharacter() function. It acts kind of similar, but you can specify easing for it.

    Imperator

    7278 Posts

  • #5, by chrisMonday, 03. April 2017, 15:09 7 years ago
    Yes, adjusting the bounding boxes seems to be the best solution.

    For the info: I tried your solution with "-10px" but no success, still the same effect going left.
    I'll look also in the Shader Toolkit, but will probably need some time to understand it well..
    Thanks again for your help !

    Newbie

    3 Posts

  • #6, by afrlmeMonday, 03. April 2017, 15:18 7 years ago
    Yes, adjusting the bounding boxes seems to be the best solution.

    For the info: I tried your solution with "-10px" but no success, still the same effect going left.
    I'll look also in the Shader Toolkit, but will probably need some time to understand it well..
    Thanks again for your help !
    You don't have to use the game.WindowResolution values. game.WindowResolution is returning the width/height of the default game resolution you specified for your game in the game properties section of the editor, so game.WindowResolution.x / 2 is default resolution width shared by 2 (half width). You could simply type something like this instead if you prefer...
    game.GameHorizontalScrollDistance = 3oo -- 300 pixels from edge of screen (x-axis)
    game.GameVerticalScrollDistance = 200 -- 200 pixels from edge of screen (y-axis)

    ... here we've told it to only scroll vertically if the character position reaches 200 pixels from the top or bottom of the current viewport (current camera position on the scene) or 300 pixels from the left or right hand side of the viewport.

    Imperator

    7278 Posts