Changing player visibility over time in lua script

  • #1, by anthonyirwin82Saturday, 19. February 2022, 04:12 2 years ago
    Hi,

    I am trying to fade my player on or off the screen for teleporting out of a room.

    The wiki is still down so I can't get access to the documentation. I believe the following should do the trick but it causes the game engine to freeze.

    I am guessing that the while loop is in an infinite loop but if the setDelay function is calling the ChangeVisibility function then the loop condition should be met after fading the character out.

    Anyway if someone can point me in the right direction it would be greatly appreciated.

    The code is below:

    visibility = 100
    player = game.CurrentCharacter
    
    function ChangeVisibility()
      visibility = visibility - 5
      player.Visibility = visibility
    end
    
    
    while (visibility >= 5)
    do
      setDelay(500, "ChangeVisibility()")
    end

    Newbie

    20 Posts


  • #2, by afrlmeSaturday, 19. February 2022, 12:41 2 years ago
    Change visibility to 0 over 1000ms without easing
    game.CurrentCharacter:to(1000, {Visibility = 0})


    Change visibility to 0 over 1000ms with easing
    game.CurrentCharacter:to(1000, {Visibility = 0}, easeQuintOut)

    Here is a link to a page of different easing types. Most of them are valid for Visionaire, but you must remember to change the names around so that In/Out/InOut is at the end instead of in the middle. You can hover over the examples to see what each different easing type does.

    Imperator

    7278 Posts

  • #3, by anthonyirwin82Sunday, 20. February 2022, 02:51 2 years ago
    Thanks

    Much easier than I was thinking.  I hope the wiki comes back soon so I can look through it properly to see what kind of documentation is there.

    Anyway, if anyone else is interested in fading characters in or out this is my final code:

    player = game.CurrentCharacter
    if (player.Visibility == 100)
    then
       player:to(1500, {Visibility = 0}, easeQuintOut)
    else
       player:to(1500, {Visibility = 100}, easeQuintOut)
    end

    Newbie

    20 Posts