Smooth camera follow

  • #1, by fulviovFriday, 06. February 2015, 17:19 7 years ago
    Hi,
    I was thinking that it would be nice to have the possibility to have a smooth camera follow, instead of the "hard stop" we have right now when the camera gets in place.
    Something like this: http://vimeo.com/118432998

    I have found this in the forum:
    http://www.visionaire-studio.net/forum/thread/smooth-scrolli...

    the script however needs a lot of tweaking, and for some reason sometimes it gets stuck in some rooms.
    I'll try to tweak it more, but I think an editor option to get this done with 1 click would be better smile

    Forum Fan

    119 Posts


  • #2, by afrlmeFriday, 06. February 2015, 17:44 7 years ago
    Hmm I believe Simon intended to replace the current camera with the openGL one. Since 4.1 or 4.0.1 (I forget which version) you could return the size (height & width) of any sprite (image) which means you could get the size of the scene background which could be used to prevent the camera in the shaderFollowCharacter() function from going past the scenes background. This would probably be the best way of having the camera smoothly follow the character or mouse (whichever you decide to assign it to).

    Imperator

    7005 Posts

  • #3, by fulviovSaturday, 07. February 2015, 21:08 7 years ago
    I had a quick look at the shader toolkit and shaderFollowCharacter() seems indeed the way to go, but yeah, there is the viewport overflow problem with the backgrounds. I'll see if I can manage to modify the function to not go over the limit and behave like the standard camera smile

    Forum Fan

    119 Posts

  • #4, by afrlmeSaturday, 07. February 2015, 21:21 7 years ago
    My solution to that would be to create a function which I would call at the beginning of each playable scene once to get the width & height of the scene. I would then add some if queries to the scroll function inside of the shader toolkit script to prevent overflow. I can't give you a script off the top of my head though.

    Imperator

    7005 Posts

  • #5, by tabbesMonday, 21. December 2020, 12:30 9 months ago
    Has anyone been able to fix the problem?
    I have the same problem with the viewport overflow.
    My workaround was:
    game:setValue(VGameScrollSpeed, 0) -- fixes the overflow
    1
    shaderFollowCharacter("", 1, 1000, easeQuintOut) -- enables smooth camera with Shader Toolkit
    1
    but then the dialogue text is no longer in the right position. Therefore:
    function adaptedTextPosition(text)
      local owner = text:getLink(VTextOwner)
      if owner:getId().tableId == eCharacters and owner:getName() == 'Typ' then
        local pos = owner:getPoint(VCharacterPosition)
        pos.y = pos.y - owner:getFloat(VCharacterSize)*3.3
        text:setValue(VTextPosition, pos)
        return true
      end
      return false
    end
    registerHookFunction("setTextPosition", "adaptedTextPosition")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    But it's definitely not clean. Any other ideas?

    (When I activate background text, the text sits in the correct position.)

    Newbie

    4 Posts

  • #6, by afrlmeMonday, 21. December 2020, 14:33 9 months ago
    Did you update to the latest version that Simon uploaded yesterday? There were some issues with the scrollposition camera in the previous build.

    Also you can technically follow the character immediately without using shaders by reducing the distance from the edge of the viewport that the character needs to be via Lua script.

    -- force camera to always move (if possible) when active character moves
    game.VerticalScrollDistance = game.WindowResoltion.y / 2
    game.HorizontalScrollDistance = game.WindowResolution.x / 2
    1
    2
    3

    it's not a super smooth effect as it moves immediately with the character, but you could I suppose subtract a bit from the value so that the character has to walk say x amount of pixels from the center to trigger it.

    Imperator

    7005 Posts

  • #7, by tabbesMonday, 21. December 2020, 15:45 9 months ago
    yes, I know this trick but I don't like the hard stops very much. I was hoping to use the easy ease functions with the shader tollkit. But I think I have to use your code because I can't get the dialogue position stable. Without my script the text sits at the right height but at the left edge of the screen. And my code does not take into account the different scaling of the character in a scene.

    What is the function behind "Show as backgrund text" in the actions tab? 
    When I check this, the text sits at the right position (above the character). So Visionaire seems to know the right position. But as soon as I deactivate the background text option, the text is again in the wrong position.

    Newbie

    4 Posts

  • #8, by afrlmeMonday, 21. December 2020, 16:00 9 months ago
    I don't know. Background text means it's running as a background process & doesn't automatically start a cutscene. I don't have a clue why one would be in the correct position & the other not in the correct position. Maybe Simon knows why it's doing that? Let's just wait & see if he responds to the thread.

    Imperator

    7005 Posts

Write post