Forum rules - please read before posting.

Anima2D character in a 2D game (positioned in screen space) How does it work?

After trying to solve it on my own for a full day and failing, I need help! (I'm a newbie)

What is the correct method of using an Anima2D character in Adventure Creator?

I'm trying to make a scene/ game purely in 2D (with "I'll position my characters in 3D space" selected, which I think = screen space option in moving and turning) I'm using Direct method for movement

Question 1: What is the main advantage of positioning in 3D space? I'm trying to create a game that looks like Night in the Woods, with only left and right movements, and I feel this would give a better look (but I'm not sure why)
I plan to have dynamic lighting (probably with the 2DDL asset) If there isn't much of a difference, then I might as well stick with the Unity 2D option for Moving and turning, and avoid a lot of confusion that screenspace brings (such as needing navmesh instead of navmesh 2D)


I have created a character and rigged and animated it in Anima2D, and then turned it into a prefab. I then brought it into my 2D with screenspace scene, and tagged it as player (layer ignore raycast, including components such as animator, rigidbody, capsule collider and player) I've given it an animation engine of Sprites Unity Complex. 

Question 2: For an Anima2D character that is to be used purely in 2D, am I supposed to set it as a Sprites unity complex? Am I supposed to give it 3D components instead of 2D components? (I would like to avoid 3D if it isn't necessary for what I want - a purely 2D game)

I followed the text tutorial on the AC website for Making a Mechanim based character, including the part with the parameters and transitions. Is this necessary for an Anima2D character? After this, the character moves very slowly, starts walking much after pressing a direction key, and begins to run randomly (not depending on pressing the shift key)

I've probably made a mess of multiple settings that don't go together.

Here are my player inspector settings :

image

image



Thanks in advance!

Comments

  • edited July 2017
    What is the main advantage of positioning in 3D space?

    You're correct about the effect of the "I'll position my characters in 3D space" option.  Screen Space mode basically means that characters move in 3D (i.e. towards and away from the camera) rather than purely along the X/Y plane.  Unlike the World Space option, it still relies on 2D components, meaning you can still place Hotspots etc down in the 2D window.  It's main use is for when you want true depth as opposed to the faking effect caused by the Sorting Map system in "normal" 2D games.

    This allows for other neat things, such as placing 3D meshes in the scene that the characters can move around.  However, similar behaviour can be achieved by using 2D characters and 2D cameras in a 3D scene.

    I would suggest you stick to Unity 2D mode, unless you have a specific need for otherwise - for the same hassle you've mentioned above.  As an additional, I'm currently revisiting these extra "Moving and turning" options as I'm not sure how relevant they are today - they were chiefly added as an interim way back before Unity implemented their own 2D mode.  Happy to take feedback regarding this, however.


    For an Anima2D character that is to be used purely in 2D, am I supposed to set it as a Sprites unity complex

    You would need 3D components for this mode, as moving around 3D space requires 3D collisions.  3D components should indeed work with 2D-animated characters - dropping the Brain2D player prefab into the 3D Demo scene should generally work so far as moving around goes.  However, again unless there's a real need to, I would suggest sticking to purely 2D components.  The Character Wizard can help you modify your starting sprite with the correct components / hierarchy.

    So far as Anima2D goes, you'd definitely want to rely on Sprites Unity Complex mode, as Anima2D requires the use of an Animator Controller to work.  There was a recent discussion on using Anima2D in AC here, which you may want to consult.
  • edited July 2017
    Thanks for the response. So from what you've said, it'd probably best for me to work in 2D and avoid Screen Space mode and 3D components for the player. (Especially since I'm relatively new to Unity and am unaware of how scripting works)

    I'm still unsure of how to make an Anima2D character work with AC using Sprites unity complex. Does this require scripting? I've set the character as you can see in the pictures I've posted above. I've specified the animator in the animator component, but I've left the animator field empty in the mecanim parameters option - Is that correct or would it create issues? EDIT: I've now created a character through the character wizard and set my anima2d character as the sprite child for this created character. Now there isn't any animator field in the mecanim parameters option, which I think is correct.

    I tried importing the sprites unity complex example file of Brain into the same scene, and Brain walks around properly. My character though, walks very slowly without any animation, then the walking animation kicks in after a while, and then he randomly begins to run.

    I'm also unsure about what the Sprite child is supposed to be here. Since I made the character with Anima2D, my character consists of different sprites for arms, legs, torso and head functioning together. What would be the sprite child in this case? Currently I've set it as the "bones" game object that was made for the character, which I'm sure is incorrect. Should I just make a new .png of the complete character sprite and make that the sprite child?  EDIT:  Created a character through the character wizard and set my anima2d character as the sprite child for this created character. (But this has had no effect on the issues I'm experiencing, the character is behaving in exactly the same way as I've specified here)

    I'm actually confused about the relation between the conditions specified in the transitions for the animator, and how they work with the movement settings of the player. Sure, keeping the walk value between 0.1 to 1 is supposed to make the character walk, but how would I make him walk faster? Isn't walk speed also determined by the walk scale value?

    In any case, that is a later issue. As of now I'm unable to make the character walk around normally. Is there anything in the screenshot and video I posted that shows what I'm doing wrong?

    Thanks
  • Update:

    I tried importing the sprites unity complex example file of Brain into the same scene, and Brain walks around properly. My character though, walks very slowly without any animation, then the walking animation kicks in after a while, and then he randomly begins to run.

    I unchecked "Has Exit Time" for each of the transitions, and now the character starts walking immediately upon pressing the button. The character can now walk forwards and backwards.

    There are still some problems -

    1. He doesn't run, and I'm not sure how that is to be done.How would the "MoveSpeed" parameter go above 1? It seems to go up to 1, not beyond that. If I increase the walk speed scale beyond 1, he then starts running

    2. The walk speed is slow, and it doesn't line up with my walking animation. How do I increase the speed of his movement? (not the animation) As I said, increasing the walk speed scale starts the running animation, rather than increase his walking speed

    3. How can I flip the sprite to make him face left when walking to the left and right when walking right? As of now he only faces the right side, and walks backward when walking to the left side. The "frame flipping" option that is present in the unity 2d mode is not available in sprites unity complex, I think.

    Thank you!


  • edited July 2017
    Fixed the run issue, the solution was ridiculously simple. Had to simply write "Run" in the name field for a new input manager function, and write left shift, right shift for positive and negative button (in case anyone else is facing the same problem)

    Also fixed the walk speed by increasing the walk speed scale and run speed scale values but then also increasing the values in the transitions conditions for "movespeed" to accommodate for these new values. Awesome!

    Now there's only the issue of the character walking backwards instead of the sprite flipping when pressing left direction button. How is this done?
  • I'm currently trying to work with blend trees, but the "direction" parameter doesn't show up as an option when selecting a parameter for the blend trees. I'm guessing this is because it is an "integer"? Movespeed shows up, and so does angle. I can't use angle as in a blend tree, it can only be adjusted between 0 and 1, not between 90, 180 and 270 for some reason, not sure why. 

    I've also tried working on the base layer, with transition for walking left set to Movespeed > 0.1 and Direction = 1 (1 is when moving left, 2 when moving right) For some reason it just plays the walking right animation, and it also begins to glitch the idle animation after that. Looking at the animator window while moving left shows that it is actually going through the transition arrows into the move left state, but it doesn't play the animation. 
  • In the case of Anima2D, I would say your "Sprite child" should be an interim child object that has both the sprites and the rig as children.  That way, AC can control its rotation (which is how it works) without it causing an offset in rotation between the sprites and the rig:

    Root Player object
    - Sprite child
    - Sprites
    - Rig

    A BlendTree can accept parameters that go beyond 0 -> 1 by unchecking "Automate Thresholds".


  • @chrisicebox Ok so I now created a GameObject and made that the player (gave it all the player components) and made my existing character its Sprite Child. I removed all the player components from the sprite child, but left the animator there to take care of the idle, walking animations etc.

    I then made a new animator controller for the new player game object, and made a new animation called walk left. I tried adding a property to this new animation: Sprite child -> rotation y 180 degrees. But for some reason it won't let me edit it to 180 degrees, it keeps returning to zero. The inspector also shows up blank. So I instead added a property: new player game object -> rotation y 180 degrees.

    In this new animator controller though, there is no change detected when I move my character. The movespeed and direction values sit at zero regardless of my button inputs. Therefore the transitions also don't kick in. The character walks normally like he did before, without flipping

    imageimage
  • edited July 2017
    So you're now using two Animators?  One on the root, one on the sprite child, correct?

    AC will only control one Animator - and if there's one on the sprite child, then that will take precedence over the base one.

    You shouldn't have to rely on two separate animators, however.  You can instead use layers - place the flipping in a base layer, with the standard animations in the next layer down.  You also shouldn't be animating the root at all - that's why a sprite child is necessary.

    What is your actual flipping animation, and what are the transitions to it?  Those are not clear in the screenshots you've posted.
  • edited July 2017
    Am I proceeding in the right direction though? I'm trying to figure out the things you have mentioned, but if there is a simpler method to flip/ mirror the character then I wouldn't mind starting over with another method.
    Would it be more straightforward to edit the AC player script for instance? Something like the transform.localscale command that I've read about while looking for solutions.
  • As for the animation, of one of the methods I tried, it was to have another game object and have that inside the root object, with the sprite child inside it, and give this new game object a Y rotation of 180 degrees
  • Try this - it's my own attempt to allow frame-flipping for Sprites Unity Complex characters.

    http://pasteall.org/476288/csharp

    Attach it to your character and fill in the fields.  You'll need to make sure your Animator still covers all angles - in the case of the included example character, all the "R" animations would be set to their "L" counterparts.

    If succesful, I'll consider incorporating it into the official release.

  • @Chrisicebox Thank you so much! I'll add this script and try to make it work. I'll get back to you with the results/ queries after a couple of days - I want to give it many good attempts and make sure I'm not asking basic questions :P

    Before that, I wanted to clarify a couple of things - The fields that I have to fill in are to replace "character" in the script with my character name right? Any other field that's to be filled in the script by me? Do my left animations need to have a particular name that will be referenced by the script? (also, which example character with R characters are you talking about?)
    And this is to be attached to the root object?  

    Sorry for all these questions, but I want to make sure I figure it out properly this time.
    Again, thanks for all the patience and help!
  • Due to the fact that this script may require tweaking from character-to-character, I've added this to the wiki instead of making it "official": http://adventure-creator.wikia.com/wiki/Frame-flipping_for_Sprites_Unity_Complex_characters

    The location of the component is not important - the Character field should be assigned as your Player's root, and the "Transform to flip" should generally be your sprite child.

    When set to Left To Right, the character will flip when facing left - meaning you can have all right-facing animations since they'll be inverted when appropriate.  Vice-versa for Right To Left.

    The script does not refer to animations by name - I just mean that your character's controller should still be set up for all angles.  If you only have right-facing animations, then the Animator should be set up to play these right-facing animations when the character is facing left (i.e. the Angle float is >0, <180).

    You can test it with the included Brain2D_SpritesUnityComplex example by opening each of the Idle, Walk and Talk BlendTrees and replacing each "_L" animation with its "_R" counterpart.
  • @chrisicebox

    Hi Chris. I just tried out this solution today and it works! I didn't realize you'd provided such an easy to implement solution. I'm still ironing out some kinks, but the flipping animations work perfectly. I'm surprised I didn't have to create any new animations or states in the animator, but only had to add the angle parameter for the existing transitions and fill in the fields for the new component.
    Again, thank you so much!
  • Thanks, Chris.
    This script is literally saving my life :)

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.