- Home /
I need help with player animation.
alright so i am really new with coding and using unity, but i got a player movement script. the problem is that i dont know how to make animations when going left right up down and idle. im making a 2d topdown btw. here is the movement script i have:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NewController : MonoBehaviour { public float MoveSpeed = 5f; public Transform movePoint; public LayerMask StopMovement;
void Start()
{
movePoint.parent = null;
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, movePoint.position, MoveSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, movePoint.position) <= 0.05f)
{
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), 0.2f, StopMovement))
{
movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f);
}
}
else if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f), 0.2f, StopMovement))
{
movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f);
}
}
}
}
}
Any help would be gladly appriciated!
Answer by Proliecan · Jun 23, 2021 at 10:28 AM
Brackeys has a great beginners Tutorial for your case:
Your answer
Follow this Question
Related Questions
How to Apply Animations to Script 1 Answer
A way to "freeze" the position of the animation? 1 Answer
Player can't move left or right while holding W and S at the same time - No code making it do that? 2 Answers
¿How to use animation for same object at different positions? 2 Answers
Change animation of 4 Way Movement Sprites moving diagonally to last used non-diagonal direction? 0 Answers