Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rotate character in 4 directions

Discussion in '2D' started by sunnychan1337, Feb 22, 2021.

  1. sunnychan1337

    sunnychan1337

    Joined:
    Dec 14, 2020
    Posts:
    8
    Hello,

    I want to allow my 2d character to turn in 4 different directions when using WASD, in a similar fashion to what is done in stardew valley. Random screenshot of an example below

    Notice how the side profile and the front profile are obviously different. I've been thinking about how to achieve this. At first I thought maybe I could swap sprite meshes using the SpriteResolver. However, since the bonestructure and animations of the front/side/rear view are different I don't think this approach will work.
    At the moment the only feasible solution I can think of is to destroy my character object every time it rotates and instantiate a new one, with the appropriate animations and rigging. But this intuitively feels like a very strange approach and kind of overkill for what seems easy but isn't (to me). Is there a better way of doing this?

    Edit: after some more thinking, I figured I could rig and animate all the profiles separately and make them children of a parent gameobject. Then I just enable/disable them with the .setActive() method, depending on whatever side I need. Is that a reasonable way of doing it? I mean it works but I dont know if this is considered an "odd" way of doing it.
     
    Last edited: Feb 22, 2021
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,343
    Check out this tutorial series.


    That video is related to the animation process, the video before it (#2) handles the movement.
     
  3. sunnychan1337

    sunnychan1337

    Joined:
    Dec 14, 2020
    Posts:
    8
    I just checked the video and there's a difference. He is using pre rendered sprite sheets. I rig my sprites in unity using the 2d Animation library. As far as I can tell, in this case just picking the animation state isn't sufficient, or am I wrong?
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,343
    So if you are rigging your sprites, you will probably have to do something similar. You are still going to need a sprite for each direction and rig each of them appropriately. But you can still use animation trees and the overall switching concept instead of instantiating a new gameobject each time. I havent worked with sprite rigging yet but I imagine you would have 4 rig animations (up, down, left, right) and the 4 sprites for those directions.