Simple Animation For Character Movement In Your 2D Top Down Game Made With Unity Software

preview_player
Показать описание
#unitymove #unitymovement #unityanimation
In this video I show you a quite simple script that helps you to move a character with cool animation.

TO BLAST! - My New Fun Relaxing Puzzle Game Available On Google Play Store

Guess The Movie Is Available On Play Market For Free For Android devices
Here is the link

If you like what I'm doing then you can support me through
or here

Or You Can Become A Sponsor Of My Channel

Thank you :-)

Previous Video
2D Top Down Grid Based Movement


So in the previous video which you can get by the link in the description I created this simple project. I recommend starting from that video actually. But this video is good enough as well. In that project my character was moving without any animation. So here I created a script that allows me to perform that simple animated movement. Here it is. Here I use a coroutine. Coroutine allowed variable will not let me start a new coroutine while the previous one is still running. Update method. Here, depending on which arrow button I pressed, I pass a direction to coroutine so my character will be moved up down left or right. Coroutine code makes that movement and animation possible. So the first block of code makes my character smaller with three steps of 0.2 and moves my character according to the given direction. The second part of coroutine makes a character bigger back and keeps him moving. The penultimate line of code just gives a character one more step to make it stick to the grid. Script is attached to my character. Hit play and see how cool it is.
Рекомендации по теме
Комментарии
Автор

Friends! I f**cked up with the script :-) Here is the correct one!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StepMove : MonoBehaviour
{
private IEnumerator goCoroutine;
private bool coroutineAllowed;

private void Start()
{
coroutineAllowed = true;
}

// Update is called once per frame
void Update()
{
if && coroutineAllowed)
{
goCoroutine = Go(new Vector3(0f, 0.25f, 0f));
StartCoroutine(goCoroutine);
}
else if && coroutineAllowed)
{
goCoroutine = Go(new Vector3(0f, -0.25f, 0f));
StartCoroutine(goCoroutine);
}
else if && coroutineAllowed)
{
goCoroutine = Go(new Vector3(-0.25f, 0f, 0f));
StartCoroutine(goCoroutine);
}
else if && coroutineAllowed)
{
goCoroutine = Go(new Vector3(0.25f, 0f, 0f));
StartCoroutine(goCoroutine);
}
}

private IEnumerator Go(Vector3 direction)
{
coroutineAllowed = false;

for (int i = 0; i <= 2; i++)
{
transform.localScale = new - 0.2f, transform.localScale.y - 0.2f);

yield return new WaitForSeconds(0.01f);
}

for (int i = 0; i <= 2; i++)
{
transform.localScale = new + 0.2f, transform.localScale.y + 0.2f);

yield return new WaitForSeconds(0.01f);
}



coroutineAllowed = true;
}
}

AlexanderZotov
Автор

These tutorials are really useful when making a big game. Really good thank you.

master_zeec
Автор

Nice Tutorial.. I love it as its short and crisp

briandsouza