Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(newbie) need help with an animator script

Discussion in 'Getting Started' started by Splooge, Apr 23, 2017.

  1. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
    Hi everyone I am new to unity and coding in general. I am having a lot of trouble getting my animations in and so that they work with the W,A,S,D keys. I had a movement script and a camera script so I was okay there, I just cannot get the animations right and linking them together in the animator is confusing. If anyone can possibly help me it would really be appreciated. Thanks
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome!

    It's not super clear what part you're struggling with exactly, so the best I can do is point you to the Animation department of the Learn section. If you post some more specific details of what you're experiencing and how that differs from the behavior you're expecting (along with some screenshots or even video to demonstrate), we can help you a bit better.
     
    JoeStrout likes this.
  3. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
    @Schneider21 thank you for getting back to me! All I am having trouble with is basic animation, I just want my character to run when I hold WASD and to do a stab animation when I use the left mouse click. Right now I can move him but he looks like a statue so I am just trying to figure out how to get his running, side and backward animations working for movement with the keys
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Chances are you want to be setting animation properties in your code that tell the Animator to play the appropriate animation. To confirm that, can you post some screenshots of what you have, like your Animator state and some of its properties?
     
  5. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Those help, for sure! The other things that would be helpful to see are the Parameters tab of the Animator and the Transition settings (click the arrow pointing from idle to running). I'm assuming you have a parameter called "Speed" that is being checked by the transition to know whether to change the state to running or not, but we'll have to look to know for sure.

    I can pretty confidently say the strafe states aren't configured properly based on how the arrows look, but I'm not an expert on the Animator, and can't provide you with a good recommendation for how to hook up those animations, unfortunately.
     
  7. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
    @Schneider21 Hey I do not see anything about speed in the parameters tab, here is a picture of that and the arrows.
     
  8. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Ah, you forgot your links, mate. :p
     
  9. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
    Last edited: Apr 24, 2017
  10. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    For the second shot, what I'm actually looking for is the panel that shows on the right side when you actually click the arrow. Should look like the first screenshot on this page.

    In any case, a big reason why you're not seeing any animation change is that your Animator is not set up to receive any information! If you want your animations to change depending on the player controller's speed (and I'm not saying that's the way you should, just that that seems to be the way you're trying to get it to work), you'll need to add a Parameter in the Animator called "Speed" that accepts a float value. Then your Transition from idle to running would have a condition that says something like "Speed greater than 1.0" or whatever you find is appropriate.

    If you haven't gone through the tutorials I linked to originally, I highly recommend them. They explain things much better than I can with my limited experience.
     
  11. Splooge

    Splooge

    Joined:
    Apr 23, 2017
    Posts:
    7
    @Schneider21 here is the screenshot from the idle state, there is one for all the states http://prntscr.com/f0fh4d also I checked a video on animation from that link you sent and apparently the code wont work in unity 5 anyway so I don't know what to do. If you know a direct link I can use that will work please let me know, I am at a stand still right now just over dumb animations hahah
     
  12. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Not the animation state, but the transition. The transition is what defines how you get from one state to the other. Here's an example from one of my projects:
    Screen Shot 2017-04-24 at 9.01.33 PM.png

    You can see on the left the list of parameters I use. On the right side, I've clicked the arrow going from Grounded to SitStation.

    Now in the Inspector, I can see the properties for that transition:
    Screen Shot 2017-04-24 at 9.02.03 PM.png

    The conditions indicate that if isSitting and hasConsole are true, the Animator state will switch to SitStation. If I click on the arrow pointing back from SitStation to Grounded, the only condition is "isSitting false".

    So then in code, when I call:
    Code (CSharp):
    1. if (posType == PositionType.SittingConsole) {
    2.     gameObj.GetComponent<Animator> ().SetBool ("isSitting", true);
    3.     gameObj.GetComponent<Animator> ().SetBool ("hasConsole", true);
    4. }
    the state gets changed properly. This works in the latest version of Unity, and is fundamentally the same as what you're doing, so API syntax differences aren't your problem, I assure you.

    However... I'm going to throw a radical idea at you: You don't even need to be doing this right now! Animation makes things look great, sure, but you can get the majority of your game done without even doing any animations at all. Use Unity cubes as placeholders and have them move around without animations. Maybe just change color or something to indicate a placeholder animation or something.

    Just something to consider.