"Set animation center" in last frame

  • #1, by tesildeen-Sunday, 08. March 2020, 12:15 5 years ago
    My question:
    Is it possible to move the center of a character's animation within an animation?
    For explanation:
    I have an animation in which the character jumps backwards. But after the animation, the character is of course in the same spot as before.
    I would like to use the "Set animation center" option to change the position in the last frame. Is that possible? Because if I move the center, it is always applied to all frames.  That doesn't help me of course.

    Newbie

    31 Posts


  • #2, by afrlmeSunday, 08. March 2020, 13:32 5 years ago
    I think you will need to manually update the position of the character. Let's say you know that at 100% the character will move 20 pixels, so you will need to calculate the actual pixel amount based on the current scale of the character.

    Add this inside of the last frame of the animation - edit as needed...

    local pos = game.CurrentCharacter.Position -- store current character position
    
    local perc = math.floor(game.CurrentCharacter.Size) -- store current character size (rounded up)
    
    local amt = 20 -- amount of pixels to offset at 100% character size
    
    
    
    local offset = (perc / 100) * amt -- calculate the offset
    
    
    
    game.CurrentCharacter.Position = {x = pos - offset, y = pos.y} -- update the character position

    Quick note: it's untested, & the example is for jumping left. edit the x, y bits of the last line as needed.

    Imperator

    7285 Posts

  • #3, by tesildeen-Friday, 13. March 2020, 09:40 5 years ago
    Thanks, I'll give it a try.

    Newbie

    31 Posts