Going crazy, how do I retrieve an actives animation direction value?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I am trying to make a prototype of a new game based around physics movement but I am constantly running into annoying inconsistencies, issues and bugs in my events because I need a consistent way to retrieve an actives animation direction. The active only have two animation directions, 0 and 16 and I need a way to retrieve these. Either 0 or 16 depending on which animation direction is playing. In the example attached the active can be steered with the arrow keys and it seems instead of getting the animation direction I get the direction the active is moving. I just don't get it and it is driving me crazy, I just need a way to actually retrieve the animation direction and if the sprite is currently playing the right or left animation, It feels like it should be the most simple and basic thing to do but I just can't find a way to do it ?

    Please login to see this attachment.

    Please login to see this attachment.

  • Dir() returns the direction of the object, not the animation that is being played.

    Please login to see this attachment.

    It is under the Animation section so it's a bit confusing but as far as I know they are totally unrelate, other than "animation" being a general term for motion of any kind.

    For what you want, one solution is to track it yourself:

    Set the name of an Alterable Value or Alterable String to "facing" or something similar, and change it when the left or right arrow key is held down. Personally I believe using strings for readability is better than a Value, until you prove you have a performance issue, or unless you really need a numerical value for math, etc.

    Code
    * Repeat while "Left Arrow" is pressed
    	 Active : Set facing to "left"
    
    * Repeat while "Right Arrow" is pressed
    	 Active : Set facing to "right"
    
    * Always
    	String : Set alterable string to facing( "Active" )

    Please login to see this attachment.

  • The steering with the arrow keys was just the most simple example I could provide and not reflective of the real behaviour in the game, the problem is that this issue is happening with a lot of different objects that does not have that direct input but are steered by angle either in their movement or their visual angle. I have attached another example that I got from Please login to see this link. before that also tries to solve this and it did it to an extent but it still causes bugs when facing straight up or straight down. There must be a way to just retrieve the sprites animations direction, I only have two animation direction and I just need to know if one or the other is currently playing in the sprite. Again it feels like the most basic simple thing so it feels insane that I can't find a solution.

    Please login to see this attachment.

  • Again in this case, you can use the same input as used in the animation/movement logic (in this case mouse position, but it could be an AI variable for instance) in order to determine which one will be selected. Just one of many ways to do this:

    Code
    * Always
    	 Player_Head : Set angle to ATan2(Y( "Player_Head" ) - YMouse, XMouse - X( "Player_Head" )) (Quality = 1)
    	Player_Head : Set direction to Angle( "Player_Head" ) / 11.25
    	Counter 3 : Set Counter to CompareIntegers( "Immediate If Object", XMouse - X( "Player_Head" ), "<", 0, 16, 0 )

    Is there some reason you don't want to use the input values and/or Alterable Values to determine the result?

  • I did just find a way to sort of do it, by using different loop values in the animation frames. This is just with 1 or 2 frames but it could work with actual animations too, such as frames 1-16 for left-facing and 17-32 for right-facing:

    Please login to see this attachment.Please login to see this attachment.Please login to see this attachment.

    Code
    * Always
    	 Player_Head : Set angle to ATan2(Y( "Player_Head" ) - YMouse, XMouse - X( "Player_Head" )) (Quality = 1)
    	Player_Head : Set direction to Angle( "Player_Head" ) / 11.25
    	Counter 3 : Set Counter to Image( "Player_Head" )
  • Can the question be rephrased again? it got a bit confusing and it seems like the question is now different from where it started, and I think I may have already answered it in a previous thread very similar to this one..

    Anyways, to answer the original question, no, you cannot retrieve animation direction directly from, at least without an extension that tracks it for you (even extensions cannot really retrieve it, they can only just try to track it automatically for you)

    Set direction and set animation direction are different, direction would set the built-in movement and animation direction at the same time, while animation direction would set the animation direction only, independent from movement direction..

    Movement direction is the only one that can be retireved directly from engine, other than that, if you really need to only manipulate the animation direction and want to retrieve it later, you will need to manually keep track of it yourself, this can be done via a value that you set everytime you set the animation direction, and whenever you want to retrieve the animation direction, you retrieve that value

    In your case, the easiest thing would be to just set the direction of the object as it also sets the animation direction, so you can retireve it anytime without the burden of having to keep track of it yourself

    ....

    The other question is unclear as I mentioned, a rephrase would help :)

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • I will try to make it as clear as possible. I am looking for a way to check if a sprite that has two animation directions is either playing its left or right animation direction.

    Like if it is playing either one of these two:

    Please login to see this attachment. Please login to see this attachment.

    I have constantly run into situations where I need to know this but no way to actually retrieve that information in a reliable way.

    "you will need to manually keep track of it yourself, this can be done via a value that you set everytime you set the animation direction"

    This does not seem to work since there are many movements that change the animation direction automatically without manual input depending on how the active is moving, like with physics movement or always updating an angle of an object like with the Please login to see this link. example above.

    The only way I have found that seems to possibly work is a formula I got from Naitor Studios of Int(( Angle( "Player_Head" ) / 11.25 + 24 ) mod 32) / 16

    From testing so far this actually seem to retrieve a value of either 0 or 1 depending on the direction of the animation. But I have not tested it enough to know that it is 100% reliable. Also having this formula running as an always event on a lot of object could possibly be performance heavy (?)

    I am still just completely baffled that there seem to be no simple way to retrieve this info from an object. It should be as simple as having an action to set a value to the objects animation direction (the actual direction of the sprite playing). I should probably open a ticket for this to see if it can be added in an update but I am not sure where one does that these days?

    Steam games: Please login to see this link.

  • I did just find a way to sort of do it, by using different loop values in the animation frames. This is just with 1 or 2 frames but it could work with actual animations too, such as frames 1-16 for left-facing and 17-32 for right-facing:

    Please login to see this attachment.Please login to see this attachment.Please login to see this attachment.

    Code
    * Always
    	 Player_Head : Set angle to ATan2(Y( "Player_Head" ) - YMouse, XMouse - X( "Player_Head" )) (Quality = 1)
    	Player_Head : Set direction to Angle( "Player_Head" ) / 11.25
    	Counter 3 : Set Counter to Image( "Player_Head" )

    This is an interesting method but I don't see how it would work properly if having say a playing walk animation in the left and right direction with 10 frames each? Unless I misunderstood something?

    Steam games: Please login to see this link.

  • Made this years ago, to retrieve the actual display direction:

    Please login to see this link.

    Please login to see this attachment.

    Ah yes thank you, Naitor mentioned this! I tried it and this is exactly what I am looking for! This is how I imagine it should have worked without having to use an extension for it in the first place.

    Do you know if using this extension vs the forumla (Int(( Angle( "Player_Head" ) / 11.25 + 24 ) mod 32) / 16) would be faster if doing as say an always event on a lot of objects?

    Also I should probably make a separate thread about this but I have been wanting to ask if there is any potential increased risk of getting the game build being flagged for virus with having more extensions in the project? If every new extension is a potential risk?

    Steam games: Please login to see this link.

  • This is an interesting method but I don't see how it would work properly if having say a playing walk animation in the left and right direction with 10 frames each? Unless I misunderstood something?

    With this approach, the first 10 frames of the right animation would be "dummy" frames essentially, just a copy of the walk-right animation cycle.

    When the active turns right there can be a delay for the frame number to be in the correct range, which could be 10 frames or could be 0 frames. So, the direction you'd get would be incorrect for up to the first 10 frames (numbered 0-9) until it gets past frame 11 and then at that point it would loop back to frame 11.

    This may or may not work for your game based on your graphics and other interactions obviously.

    In this clip, I have the frame speed set to 10 so it's easier to see the values changing:

    Please login to see this attachment.
  • The only way I have found that seems to possibly work is a formula I got from Naitor Studios of Int(( Angle( "Player_Head" ) / 11.25 + 24 ) mod 32) / 16

    From testing so far this actually seem to retrieve a value of either 0 or 1 depending on the direction of the animation. But I have not tested it enough to know that it is 100% reliable. Also having this formula running as an always event on a lot of object could possibly be performance heavy (?)

    This is not heavy at all, it's a very light calculation actually, this not the type of thing that results in any slowdowns whatsoever..

    ...

    It's really simpler than what it seems, while you can't directly retrieve the actual displaying animation direction, you can kinda retrieve it via other means as explained above, or by just using the extension that defisym made (note that it's windows only)
    Though your question is actually different than retieving the actual animation direction, you want to calculate the direciton based on an angle of an object, which they are different and NOT connected

    • Angle is the rotation of an object, the displayed one, not related to Direction or animation direction (physics movements can automatically set the angle of an object though, but still, not related to directions or animation directions)
    • Direction is related to built-in movements, even physics, though in terms of physics I would recommend using the velocity angle expression instead, as physics are 360 based and direction can truncate them to 32, which is missing data
    • Animation direction cannot be retrieved directly, though can be retireved via other means as I just explained

    Anyways, to retrieve a 32 direction from a 360 angle, you will just do Angle( "Player_Head" ) / 11.25 why 11.25? because 360/32 = 11.25
    And in terms of wanting to know if an object specifically facing left or right via binary values (0 and 1) Naitor already gave you the calculation for that, which is Int(( Angle( "Player_Head" ) / 11.25 + 24 ) mod 32) / 16

    I am still just completely baffled that there seem to be no simple way to retrieve this info from an object. It should be as simple as having an action to set a value to the objects animation direction (the actual direction of the sprite playing). I should probably open a ticket for this to see if it can be added in an update but I am not sure where one does that these days?

    While I agree that it should be an expression, this was suggested multiple times already, I think the answer was it would be hard to implement due to how Fusion internals work, but I may be mistaken..

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • Also I should probably make a separate thread about this but I have been wanting to ask if there is any potential increased risk of getting the game build being flagged for virus with having more extensions in the project? If every new extension is a potential risk?

    No, not really, just make sure to build with "Unpacked EXE" option enabled in app properties, this extracts all the DLLs (like extension and runtime DLLs) and the main .dat file out of the exe, which greatly decreases false positives

    While some extension DLL files may be marked as not safe, this is a bit rare.

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • With this approach, the first 10 frames of the right animation would be "dummy" frames essentially, just a copy of the walk-right animation cycle.

    Please login to see this attachment.

    I see, it is an interesting potential workaround to the problem but I think it would be kind of a pain in the long run to implement with everything :)

    This is not heavy at all, it's a very light calculation actually, this not the type of thing that results in any slowdowns whatsoever..

    That is good! I might actually only have to use this as an always event for the main character and not other characters so I think if this formula gives consistent output without fail that it will be good.


    Though your question is actually different than retieving the actual animation direction, you want to calculate the direciton based on an angle of an object, which they are different and NOT connected

    My question is really this: How to retrieve if the object (character in this case) is either playing its left or his right sprite direction :) That is the essential of what I need to retrieve to base other actions on it. For example I need to check if the guns sprite is facing left or right to know if when I create a shell casing when firing if it should be ejected with force to the left or right depending on which way the gun is facing (its graphical sprite) (left or right)

    No, not really, just make sure to build with "Unpacked EXE" option enabled in app properties, this extracts all the DLLs (like extension and runtime DLLs) and the main .dat file out of the exe, which greatly decreases false positives

    While some extension DLL files may be marked as not safe, this is a bit rare.

    Ah I see, I always have unpacked exe checked so that is good! But if I understand this then there is very unlikely and rare for an extension to be marked as a false positive, but it is not impossible? So for example if you have a game with 10 extensions vs another with 100 extensions it is more likely the one with 100 would be flagged with a false positive?

    Steam games: Please login to see this link.

  • Ah yes thank you, Naitor mentioned this! I tried it and this is exactly what I am looking for! This is how I imagine it should have worked without having to use an extension for it in the first place.

    Do you know if using this extension vs the forumla (Int(( Angle( "Player_Head" ) / 11.25 + 24 ) mod 32) / 16) would be faster if doing as say an always event on a lot of objects?

    Also I should probably make a separate thread about this but I have been wanting to ask if there is any potential increased risk of getting the game build being flagged for virus with having more extensions in the project? If every new extension is a potential risk?

    You can benchmark it, usually extension is much faster than fusion events.

    But the implement of this expressions is different than your formula, it will read the animation header of active object, find which direction is empty and which has animation, then calculate the result based on previous direction. So it needs more calculation.

    But if you change animation later(8 dir to 4 dir), you don't need to modify the formular.


    And for virus, actually IDK, but my game with several custom extensions passed steam verification with no false positive.

  • I might have to go with the

    You can benchmark it, usually extension is much faster than fusion events.

    But the implement of this expressions is different than your formula, it will read the animation header of active object, find which direction is empty and which has animation, then calculate the result based on previous direction. So it needs more calculation.

    But if you change animation later(8 dir to 4 dir), you don't need to modify the formular.


    And for virus, actually IDK, but my game with several custom extensions passed steam verification with no false positive.

    Tried some more and the formula was actually not 100% reliable and "bugged out" so it seems the WinApi object is perhaps the only way!

    Please login to see this attachment.

    Steam games: Please login to see this link.

  • The WinAPI extension is a good choice, and has some terrific features that I use myself. But you can also achieve this with the Animation Info object. This expression will give you the real animation direction (and not the movement direction):

    Please login to see this picture.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!