flexible character animation

  • #1, by zheWednesday, 18. March 2015, 14:08 5 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.

    http://www.visionaire-studio.net/forum/thread/flexible-talka...

    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.

    http://www.visionaire-studio.net/forum/thread/how-to-check-t...

    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

    Zhe

    Newbie

    28 Posts


  • #2, by afrlmeWednesday, 18. March 2015, 15:39 5 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
    startAnimation(Animations[a.."_e"])
    elseif c >= 24 and c <= 68 then -- south east
    startAnimation(Animations[a.."_se"])
    elseif ...
    ...
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    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.
    1
    2

    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.

    Imperator

    6815 Posts

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

    Newbie

    28 Posts

  • #4, by zheWednesday, 18. March 2015, 19:48 5 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
    startAnimation(Animations[useinv"_e"])
    elseif c >= 24 and c <= 68 then -- south east
    startAnimation(Animations[useinv"_ne"])
    elseif c >= 69 and c <= 113 then
    startAnimation(Animations[useinv"_n"])
    elseif c >= 114 and c <= 158 then
    startAnimation(Animations[useinv"_nw"])
    elseif c >= 159 and c <= 203 then
    startAnimation(Animations[useinv"_w"])
    elseif c >= 204 and c <= 248 then
    startAnimation(Animations[useinv"_sw"])
    elseif c >= 249 and c <= 293 then
    startAnimation(Animations[useinv"_s"])
    elseif c >= 294 and c <= 338 then
    startAnimation(Animations[useinv"_se"])
    end
    end]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22




    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
    startAnimation("Animations[useinv_e]")
    -- North East
    elseif char:getInt(VCharacterDirection) >= 24 and char:getInt(VCharacterDirection) <= 68 then
    startAnimation("Animations[useinv_ne]")
    -- North
    elseif char:getInt(VCharacterDirection) >= 69 and char:getInt(VCharacterDirection) <= 113 then
    startAnimation("Animations[useinv_n]")
    -- North West
    elseif char:getInt(VCharacterDirection) >= 114 and char:getInt(VCharacterDirection) <= 158 then
    startAnimation("Animations[useinv_nw]")
    -- West
    elseif char:getInt(VCharacterDirection) >= 159 and char:getInt(VCharacterDirection) <= 203 then
    startAnimation("Animations[useinv_w]")
    -- South West
    elseif char:getInt(VCharacterDirection) >= 204 and char:getInt(VCharacterDirection) <= 248 then
    startAnimation("Animations[useinv_sw]")
    -- South
    elseif char:getInt(VCharacterDirection) >= 249 and char:getInt(VCharacterDirection) <= 293 then
    startAnimation("Animations[useinv_s]")
    -- South East
    elseif char:getInt(VCharacterDirection) >= 294 and char:getInt(VCharacterDirection) <= 338 then
    startAnimation("Animations[useinv_se]")
    end
    end]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30


    Thanks for your effort to help me out AFRLme smile

    Newbie

    28 Posts

  • #5, by afrlmeWednesday, 18. March 2015, 20:34 5 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.

    Imperator

    6815 Posts

Write post