Search Unity

Okay I'm getting Aggrivated with Standard Assets Mobile(Animations)

Discussion in 'Scripting' started by N1warhead, Nov 22, 2014.

  1. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Okay guys, I've been sitting here for days trying to figure out how to play walking animations
    with the mobile joysticks.

    I've gotten varying results that either half way work or dont work at all.

    So far the only place I see them working is in PlayerRelativeControl.js
    However, if I put

    if(moveJoystick.position.y == 0){
    anim.SetFloat("Walk", 0); <<<<<<<< This accesses Animator Component and changes to Idle animation.
    }

    if(moveJoystick.position.y < 0){
    anim.SetFloat("Walk", 1); <<<<<<<< This accesses Animator Component and changes to Walk animation.
    }

    if(moveJoystick.position.y > 0){
    anim.SetFloat("Walk", 1); <<<<<<<< This accesses Animator Component and changes to Walk animation.
    }



    The very last IF overrides everything and just automatically plays the animation.
    Is there another way to do this? I'm seriously about to just give up Mobile development, I have seen nothing ANYWHERE about this.
    Something tells me it is something simple, but I for one don't understand UNITYSCRIPT, and two, am quite new to mobile development.


    If anyone can help me PLEASE for the mother of god please help me!
    I've been avoiding this problem for weeks and just started tackling it like 4 days ago and I just can't figure this out.

    All I want to do is when I move Joystick up and down to play the animation I put
    anim.SetFloat("Walk", 1);
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You're treating a float like an int, why? position.y == 0 will only be really zero sometimes. Use if (Mathf.Abs(moveJoystick.position.y)<0.1f) or such - ie close to zero. You can't compare == with floats.

    I'd use something like:

    Code (CSharp):
    1. if (Mathf.Abs(moveJoystick.position.y)<0.1f)
    2. {
    3.     anim.SetFloat("Walk", 0);
    4. }
    5. else
    6. {
    7.     anim.SetFloat("Walk", 1);
    8. }
    But you'll want to prevent the character moving while <0.1f as well. This way, it has the deadzone, it has consistency etc. And passing in the actual moveJoystick.position.y value into float might be better so you can blend between idle, walk and run.
     
    angrypenguin likes this.
  3. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884

    I was just working off of the code that the premade script already had, which was
    Unityscript confuses the crap outta me, but I'll try what you put.

    Hope that works lol.
     
  4. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    OMG THANK YOU SO MUCH MAN, IT WORKS!
     
  5. Crival

    Crival

    Joined:
    Sep 3, 2014
    Posts:
    21
    excuse me... can you also help me on how to implement the walk animation in the standard assets (mobile)???
     
  6. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884

    anim.SetFloat("Walk", 0);


    That is how you do it.

    public Animator anim;

    anim.SetFloat("NameOfVariableInsideOfAnimator", 1);
     
  7. Crival

    Crival

    Joined:
    Sep 3, 2014
    Posts:
    21
    Do I use the Player Relative Control(this is from the standard asset for mobile which I am currently using) for the scripting???
     
  8. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    Yes