Search Unity

Can someone help me on my simple animation controller?

Discussion in 'Unity Certification' started by asrikhidzi, Mar 18, 2018.

  1. asrikhidzi

    asrikhidzi

    Joined:
    Mar 18, 2018
    Posts:
    1
    Hi guys! Can someone help me with my animation controller. I'm new in unity and i try to use animation to my character on grab and pushing object. On walking and idle I've no problem. Here my sample coding for animation.

    static Animator a;
    private Vector3 movedir = Vector3.zero;
    private Rigidbody controller;

    void Start () {
    controller = GetComponent<Rigidbody> ();
    speedchange = speed;
    move = false;
    a = GetComponent<Animator> ();
    }

    void Update () {
    movedir = new Vector3 (0f, 0f, Input.GetAxis ("Vertical"));
    movedir = transform.TransformDirection (movedir);
    transform.Rotate (0, Input.GetAxis ("Horizontal")* rotatespeed, 0);
    movedir = (movedir * speedchange) * Time.deltaTime;
    controller.MovePosition (controller.position + movedir);

    if (Input.GetButtonDown ("Vertical")) {
    move = true;
    }else if (Input.GetButtonUp ("Vertical")) {
    move = false;
    }

    if (move) {
    a.SetTrigger ("walk");
    }else if (!move ) {
    a.SetTrigger ("idle");
    }else if (!move && p.beingCarried) {
    a.SetTrigger ("grab");
    }else if (move && p.beingCarried) {
    a.SetTrigger ("push");
    }
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,789
    1. Wrong section in the forums.

    2. Please use code tags : https://forum.unity.com/threads/using-code-tags-properly.143875/

    3. Assuming that p.beingCarried is set correctly, the way you have set up your code is that, let's say you want to play grab (so move == false and p.beingCarried == true), at this line : else if (!move ), it stops evaluating further, since the condition is fulfilled so there is no "else". The quickest fix would be to reorder the if statements, so the bottom two are evaluated first.