flexible character animation

  • #1, by zheWednesday, 18. March 2015, 14:08 9 years ago
    Dear Visionaire Community,

    since 2 months I have been following this forum, working the same time on a own project and want to thank you guys for your tips, tricks and tutorials here in the forum and out there.
    So far I was able to solve everything for my needs with the logical bricks and got everything what I need.
    However, purely for the cosmetics I have a concern that can be apparently solved with lua_script,
    the problem is that I have no experience about programming with lua or anything else.
    For you to get an overview of what it is in gerneral, I have attached a few screens below.

    My specific PROBLEM ist the following:
    I want to allow the character to bring up a corresponding animation to the current direction.

    I have found the following threads here in the forum:
    This one of Suro, many thanks to them for the video tutorials by the way.


    Then those of Marvel, where AFRLme has shown an example:
    This script seems to fit perfectly for my needs, but unfortunatley I can´t integrate it in my work.


    In addition I should say that my work so far managed without a script and i`m not even sure if my attempt to integrate this „adapted from me“ script from AFRLme was correct or not.

    I got the script and:

    -Added the name of the character: char_zhe
    -Added the names of animations: useinv_back . . . . .
    ( I have this as „person_animation“ saved)
    -I tried to run the script with the „script call“ and „script run“ function
    ( I think one function should be enough right?)

    Would be great if someone could help me out.

    Thank you already in advance



    28 Posts

  • #2, by afrlmeWednesday, 18. March 2015, 15:39 9 years ago
    Um it's actually AFRLme, not AFTLme, but... no worries! grin

    I believe in the current public build is a new alignment query option which allows you to define the range from x to y degrees, which means that you can use that for checking which direction the character is currently facing. So in other words this can now be done with action parts or Lua script.

    I think the script you are using is really old. These days I tend to make scripts like that more global, so that they can be reused without having to bother writing out a new script each time.

    Quick example (incomplete)...
    function playCustomAnim(c, a)
     c = Characters[c].Direction
     -- + --
     if c >= 338 and c <= 23 then -- east
     elseif c >= 24 and c <= 68 then -- south east
     elseif ...

    So with that in mind we would call it like so...
    playCustomAnim("Tom", "use") -- check direction of character tom & then play animation use_direction-prefix.

    So in order to use a global function you would need to make sure you add the correct prefix to each of your custom animations.

    Like I said though: this is just a quick example. I've only provided a short snippet. In regards to the range values above: they are based on an 8 direction character with 45º per direction. The correct range for each direction should be plus / minus 22.5º on either side of each directions degree, but decimal values are not allowed so you would need to do -22 & + 23 to make up 45º...

    Oh dear I seem to have rambled on a wee bit. Anyway, good luck with your project & hopefully you will be able to figure something out.


    7278 Posts

  • #3, by zheWednesday, 18. March 2015, 16:09 9 years ago
    Thanks for your quick response AFRLme, I will test it out soon.
    Hope I can handle this.


    28 Posts

  • #4, by zheWednesday, 18. March 2015, 19:48 9 years ago
    Hey AFRLme,

    I have worked with this version of your suggestion,

    [function playCustomAnim(c, a)
     c = Characters[c].Direction
     -- + --
     if c >= 338 and c <= 23 then -- east
     elseif c >= 24 and c <= 68 then -- south east
     elseif c >= 69 and c <= 113 then 
     elseif c >= 114 and c <= 158 then 
     elseif c >= 159 and c <= 203 then 
     elseif c >= 204 and c <= 248 then 
     elseif c >= 249 and c <= 293 then 
     elseif c >= 294 and c <= 338 then 

    but it plays no animation.
    While I worked at this version, I have tested your old version and fitted this with the new coordinates and it works fine for me.

    [local char = game:getLink(VGameCurrentCharacter)
    function checkDir()
     -- East
     if char:getInt(VCharacterDirection) >= -22 and char:getInt(VCharacterDirection) <= 23 then
     -- North East
     elseif char:getInt(VCharacterDirection) >= 24 and char:getInt(VCharacterDirection) <= 68 then
     -- North
     elseif char:getInt(VCharacterDirection) >= 69 and char:getInt(VCharacterDirection) <= 113 then
     -- North West
     elseif char:getInt(VCharacterDirection) >= 114 and char:getInt(VCharacterDirection) <= 158 then
     -- West
     elseif char:getInt(VCharacterDirection) >= 159 and char:getInt(VCharacterDirection) <= 203 then
     -- South West
     elseif char:getInt(VCharacterDirection) >= 204 and char:getInt(VCharacterDirection) <= 248 then
     -- South
     elseif char:getInt(VCharacterDirection) >= 249 and char:getInt(VCharacterDirection) <= 293 then
     -- South East
     elseif char:getInt(VCharacterDirection) >= 294 and char:getInt(VCharacterDirection) <= 338 then

    Thanks for your effort to help me out AFRLme smile


    28 Posts

  • #5, by afrlmeWednesday, 18. March 2015, 20:34 9 years ago
    Because you made a mess of the example I posted grin

    a.. was a variable plus a joiner so that it combined what was contained "a" with "_prefix"

    So if the direction returned east then it would have been (based on my example) use_e.

    The problem with the second script is that you will have to create one for each interaction where you want it to select the animation based on the direction. What I was trying to show you was an example that would work for all interactions by just creating an execute a script action part & then including the name of the character whose animations you wanted to access, as well as the non-prefix part of the animation name.


    7278 Posts