Forum begins after the advertisement:


[General] Adding a Dash Animation

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [General] Adding a Dash Animation

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #13594
    Cam
    Level 21
    Participant
    Helpful?
    Up
    0
    ::

    Heys guys
    so ive added dah to the player working well.
    the thing im stuck with is animating the dash

    ill post my new playerAnimator.cs so you can see

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PlayerAnimator : MonoBehaviour
    {
        //References
        Animator am;
        PlayerMovement pm;
        public bool isDashing;
    
        SpriteRenderer sr;
    
        void Start()
        {
            am = GetComponent<Animator>();
            pm = GetComponent<PlayerMovement>();
            sr = GetComponent<SpriteRenderer>();
        }
    
        void Update()
        {
            if (pm.moveDir.x != 0 || pm.moveDir.y != 0)
            {
                am.SetBool("Move", true);
                am.SetBool("isDashing", false);
    
                SpriteDirectionChecker();
            }
            else
            {
                am.SetBool("Move", false);
            }
                if (isDashing)
                {
                    am.SetBool("isDashing", true);
                    am.SetBool("Move", false);
    
                }
        }
    
        void SpriteDirectionChecker()
        {
            if (pm.lastHorizontalVector < 0)
            {
                sr.flipX = true;
            }
            else
            {
                sr.flipX = false;
            }
        }
    }

    not sure if ive done it right but looks right but now working, wont change in the animator

    https://drive.google.com/file/d/1L4yCyyG0_W_6n_R2BCAww74rhHQIJpHH/view?usp=sharing

    happy to also show my dash code if anyone wants it

    #13595
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Cam, instead of using a boolean, it will be better to use a trigger for the dash animation. Then, in your Animator, set the exit transition of the dash animation to have an Exit Time of 1 back to the Idle or Run animation. This way, when you trigger the dash animation, it will naturally play once, then go back to the previous animation.

    #13599
    Cam
    Level 21
    Participant
    Helpful?
    Up
    0
    ::

    Your Amazing got it done !!!!!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: