This question was
closed Aug 20, 2020 at 09:49 PM by
ahsanmoindev for the following reason:
I figured out the answer.
How do I make my animation code work on both axes?
I made a script for top down movement with animations but the animation on plays on the x axis. How do I make it work on BOTH axes?
Code:
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
private Rigidbody2D rb;
private Animator anim;
Vector2 movement;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
if (movement.y != 0)
{
anim.SetBool("isRunning", true);
}
if (movement.y == 0)
{
anim.SetBool("isRunning", false);
}
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
if (movement.x != 0)
{
anim.SetBool("isRunning", true);
}
if (movement.x == 0)
{
anim.SetBool("isRunning", false);
}
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
Comment