So go ahead to your project window and look for the sprite mole and drag it to your scene. Since we’re working on melee attacks, obviously, we’ll need enemies to test out our attacks. Save all your script and go back to Unity. Rigidbody.MovePosition(rigidbody.position + movement * movementSpeed * Time.fixedDeltaTime) Hf = movement.x > 0.01f ? movement.x : movement.x 0.01f ? movement.y : movement.y < -0.01f ? 1 : 0 Movement.y = Input.GetAxisRaw("Vertical") Movement.x = Input.GetAxisRaw("Horizontal")
#CHANGE TO 2D PROJECT UNITY 2019 UPDATE#
Start is called before the first frame update Public class PlayerMovement : MonoBehaviour Now that we’re down with Player animation and Animator, let’s proceed to create the script to control our player attacks and its animations.Ĭreate a new C# script and name it PlayerAttack.cs then assign it to your Player game object. Next, we’re going to create transitions from all of our previous animations to our attack animations.įor Any State to Attack Up, set the condition, Vertical greater than 0.1 and Is_attacking to true.įor Attack Up to Idle, set the condition, Vertical less than 0.1 and Is_attacking to false.įor Any State to Attack Down, set the condition, Vertical less than -0.1, Is_attacking to true, and Is_Moving_Side to false.įor Attack Down to Idle, set the condition, Vertical greater than -0.1 and Is_attacking to false.įor Any State to Attack Side, set the condition, Horizontal greater than 0.1, Is_attacking to true, and Is_Moving_Side to true.įor Attack Side to Idle, set the condition, Horizontal less than 0.1 and Is_attacking to false.
#CHANGE TO 2D PROJECT UNITY 2019 PLUS#
Next, select Parameters tab, then click on the plus button and select Bool to create a boolean animator parameter.Ĭlick again the plus button and select Bool and name the parameter Is_Moving_Side. Open your animator window by going to Window Tab > Animation > Animator. Now that we have set up our player attack animations, let’s proceed to our animator and create a new parameter to help our animator change from either idle animation to attack animation or walking to attacking. You should have the following animations.
Move the second keyframe in 0:10 and move the last keyframe in 0:20.Ĭreate new animations for Attack_Up and Attack_Side.
Next, adjust the keyframes in the timeline. Next, go to your project window and look for the folder hero-attack-front and drag all the sprites into the animation timeline. Next, select the drop-down menu for the list of animations. Make sure you select your Player object and go to your animation window. Since we have already created a script for our player, let’s go back to our animation window (CTRL + 6) and add create animations.
If you have already followed our previous lesson then you should be able to make your character move around the platform. Read more: Unity 2D Animation: Top-Down Unity Player Movement If by any chance, you haven’t followed the said tutorial, we suggest reading it before proceeding with this tutorial. We’ll be using the same project that we have created in the last Unity tutorial which is the top-down player movement tutorial.