Forum rules - please read before posting.

Switching player character to strafing animations.

edited April 2023 in Technical Q&A

In the game me and my student are creating, the player character can switch to a combat stance when facing enemies. This means that up and down movements no longer trigger the up and down animations, just left and right. And the animations change as well. When trying to work this out, we ran into three issues.

  1. While I know that changing the player animation to custom and only selecting right and left works mostly okay, we need a way to switch out these options by code. I do not know how to access these checkboxes using a C# script.

  2. I don't know how to change the animation prefix by code either. Something like changing the player walk animation from Player_Walking_L to Player_CombatWalking_L in the C# script.

  3. When the player has only left and right movement, the animation defaults to left when moving straight up and down. I am not sure how to correct this.

Comments

  • The Manual's "Character scripting" chapter details how you can access the Player character through script. The Player is a subclass of AC's Char class, public functions and variables for which can be found in the Scripting Guide.

    You can update their walk animation with:

    KickStarter.player.walkAnimSprite = "Player_CombatWalking";
    

    You can alter the Player's animation engine to Custom with:

    KickStarter.player.animationEngine = AnimationEngine.Custom;
    

    However, I don't recommend affecting the animation engine at runtime. If you are normally using "Sprites Unity", you are better off relying instead on "Sprites Unity Complex", which better supports custom animation needs.

    This mode fits better with Unity's standard practives, as it relies on the use of Animator parameters to determine what animation is played. An example variant of the 2D Demo's Brain player can be found in /Assets/AdventureCreator/2D Demo/Resources/Brain_SpritesUnityComplex.

    Using this, you could introduce a new Bool parameter, named e.g. "InCombat", that uses transitions to cause a different set of animations to play when True.

  • @ChrisIceBox I see. And what about the last issue with the animation defaulting to left when moving up and down?

  • When using "Sprites Unity", it's a case of setting the character's Facing directions field, which defaults to Four.

    If you set this to Custom, you can then check boxes for the specific directions you want to enable.

    Through script, you can modify these by calling the SetDirections function in the character's spriteDirectionData property, i.e.:

    KickStarter.player.spriteDirectionData.SetDirections (...);
    

    This step is unnecessary, however, if you rely on "Sprites Unity Complex" for their animation engine - since the alternate set of animations played when the "InCombat" parameter is True can specify what directional animations play given an angle.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.