How to check the orientation of a character

  • #1, by marvelTuesday, 10. December 2013, 14:26 7 years ago
    Hey guys,
    i have a "combine"-Animation for my character. This animation should be played when the person combines 2 items.

    Unfortunately i don't know to which direction the character currently stands. How can i check that and play the fitting animation via lua? smile

    Key Killer

    598 Posts


  • #2, by afrlmeTuesday, 10. December 2013, 15:17 7 years ago
    We would have to check the characters alignment based on degrees & use if queries to determine the exact direction based on a value between a & b which would vary depending on the amount of character directions you are using.

    example:
    if degree value is more than or equal to a and less than or equal to b then
    start animation (some animation)
    elseif ...
    1
    2
    3
    4

    I'm not sure on the exact values of what you need to check between at the minute as for instance: 8 character directions equals 45 degrees per direction, so one of the directions could be between 0 & 45 degrees & the next between 45 & 90 etc & so on.

    Imperator

    6812 Posts

  • #3, by AlexTuesday, 10. December 2013, 16:08 7 years ago
    or make it generic and use the animation where
    math.abs(character:getInt(VCharacterDirection) - anim:getInt(VAnimationDirection))
    returns the minimum value.

    Great Poster

    378 Posts

  • #4, by afrlmeTuesday, 10. December 2013, 16:19 7 years ago
    hmm...

    I have written this:
    local char = game:getLink(VGameCurrentCharacter)

    function checkDir()
    -- East
    if char:getInt(VCharacterDirection) >= 0 and char:getInt(VCharacterDirection) <= 44 then
    startAnimation("Animations[add animation name here]")
    -- North East
    elseif char:getInt(VCharacterDirection) >= 45 and char:getInt(VCharacterDirection) <= 89 then
    startAnimation("Animations[add animation name here]")
    -- North
    elseif char:getInt(VCharacterDirection) >= 90 and char:getInt(VCharacterDirection) <= 134 then
    startAnimation("Animations[add animation name here]")
    -- North West
    elseif char:getInt(VCharacterDirection) >= 135 and char:getInt(VCharacterDirection) <= 179 then
    startAnimation("Animations[add animation name here]")
    -- West
    elseif char:getInt(VCharacterDirection) >= 180 and char:getInt(VCharacterDirection) <= 224 then
    startAnimation("Animations[add animation name here]")
    -- South West
    elseif char:getInt(VCharacterDirection) >= 225 and char:getInt(VCharacterDirection) <= 269 then
    startAnimation("Animations[add animation name here]")
    -- South
    elseif char:getInt(VCharacterDirection) >= 270 and char:getInt(VCharacterDirection) <= 314 then
    startAnimation("Animations[add animation name here]")
    -- South East
    elseif char:getInt(VCharacterDirection) >= 315 and char:getInt(VCharacterDirection) <= 359 then
    startAnimation("Animations[add animation name here]")
    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


    I was a little confused about what to add as the values as according to the animation direction compass each 45 degree mark is a new direction.
    * 0 = east
    * 45 = north east
    * 90 = north
    etc...

    so I added the values like so: 0 to 44, 45 to 89 etc.

    Imperator

    6812 Posts

  • #5, by afrlmeTuesday, 10. December 2013, 18:21 7 years ago
    hmm it won't let us call mirrored animations as they don't seem to exist in the animations table so it just returns an error about not finding it in the table & another error for trying to play an animation that doesn't exist.

    Imperator

    6812 Posts

Write post