I'm using unity version 2022.3.20f1, and v1.83.0 of AC.
In my 2D sidescrolling point-and-click, the player can move in all 8 directions, but I'm only making different animations for left and right. When the player moves straight up or straight down, I want the direction of the walk animation to be the same as the direction they were just facing. I changed the 'facing directions' attribute on the player to custom, and only select left and right. However, when I make the player walk straight up or straight down, his walking/running animation automatically faces left, regardless of whatever direction he was facing before pressing the button. His other animations are normal. Is there a way I can check for what direction the player is facing, and set the up and down walking animation to be either depending on the direction?
Thank you for your help.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You'd need to switch the Player's Animation method field to Sprites Unity Complex, as this allows you to rely on Animator parameters to control which animations are played and when.
If you define a "Direction integer" parameter in both the Animator Controller, and the Player's Inspector, this will be set to their facing direction at runtime. You can get a list of what value corresponds to each direction in the Manuals "Character animation (Sprites Unity Complex)" chapter.
It should then just be a case of creating transitions between the different direction animations that only kick in when this parameter is set to either the left- or the right- direction value.
I followed your instructions and it does work, however for some reason the same problem occurs when moving straight up or down. I'm not sure why this is the case, since I made very certain that the direction only switches from right-facing to left-facing when the Direction integer = 1, meaning left (and vice-versa). Therefore, the character's sprite shouldn't be defaulting to left when Direction = 3 (straight up) or 0 (straight down), it should just play the walk/run animation of the direction that the idle was facing. I would like to debug this by possibly using GetComponent to find the value of the 'Direction' variable during gameplay and printing it to the console. I tried looking for where exactly that variable is defined, mostly in the 'Player' script and I feel pretty lost. Kinda feel like I don't really know what I'm doing so any help is greatly appreciated.
Sounds like you're looking for GetSpriteDirectionInt, which is in the Char class that Player derives from.
Either can be used - but the Idle -> Walk transition is based on the Move Speed. You'll need to create transitions that cause the character to play the correct directional walking animation when they move.
Solved! Thank you so much for your help. I found the root of the problem. It was a lot more simple than I was making it. I originally had 'Facing directions' set to custom, with only two options, left and right. My thinking was I should have it set to that since those are the only sprites I wanted to show. However, because the character can move up and down, I need to have it set to four facing directions, even if I'm not planning to make a distinct 'up' or 'down' walk sprite. The animator now correctly uses the direction facing last to walk straight up and down.
Hi, sorry to pick this back up again, it's been basically a month since it was settled. It's not that this solution doesn't work, but after working with it for a little bit I realized how unfeasible it would be to have to animate a left-facing copy of every other animation from scratch. I tried to flip the animation various ways, or turning the 2D rig to face the other direction, but that works about as well as you'd think. What's got me scratching my head is, when I was using Sprites Unity, there was simply a box I could tick to flip the animations I made to make the left facing ones. So I know it is possible, but since switching over to Sprites Unity Complex, I don't know what that would equate to putting into code.
A single sprite-based character can have their "Flip X" checkbox checked, but for a rig-based character it's typically a case of inverting their X-scale value.
A script on the AC wiki should handle this:
https://adventure-creator.fandom.com/wiki/Frame-flipping_for_Sprites_Unity_Complex_characters