Skip to main content
added 3 characters in body; edited tags
Source Link

I want to make my 2D top-down walking animation stop and revert to the idle animation while continuing to face in the same direction as the previous movement.

For example, when I go up then stop, my character should continue to look up. If I go down, it should continue to look down.

I use lastmoveX and lastmoveY floats for idle and for walking I use moveX and moveY floats. moveX and moveY change when I move with the joystick, but lastmoveX and lastmoveY do not change, and I don't know how to fix this.

Here is my code:

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

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D myRB;
    private Animator myAnim;
    public Joystick joystick;
    public MoveByTouch controller;

  

    [SerializeField]
    private float speed;

    // Use this for initialization
    void Start ()
    {
        myRB = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();

    }
    
    // Update is called once per frame
    void Update ()
    {
        myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

        myAnim.SetFloat("moveX", myRB.velocity.x);
        myAnim.SetFloat("moveY", myRB.velocity.y);

        if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
        {
            myAnim.SetFloat("lastMoveX", joystick.Horizontal);
            myAnim.SetFloat("lastMoveY", joystick.Vertical);
        }

       
    }
}

I want to make my top-down walking animation stop and revert to the idle animation while continuing to face in the same direction as the previous movement.

For example, when I go up then stop, my character should continue to look up. If I go down, it should continue to look down.

I use lastmoveX and lastmoveY floats for idle and for walking I use moveX and moveY floats. moveX and moveY change when I move with the joystick, but lastmoveX and lastmoveY do not change, and I don't know how to fix this.

Here is my code:

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

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D myRB;
    private Animator myAnim;
    public Joystick joystick;
    public MoveByTouch controller;

  

    [SerializeField]
    private float speed;

    // Use this for initialization
    void Start ()
    {
        myRB = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();

    }
    
    // Update is called once per frame
    void Update ()
    {
        myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

        myAnim.SetFloat("moveX", myRB.velocity.x);
        myAnim.SetFloat("moveY", myRB.velocity.y);

        if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
        {
            myAnim.SetFloat("lastMoveX", joystick.Horizontal);
            myAnim.SetFloat("lastMoveY", joystick.Vertical);
        }

       
    }
}

I want to make my 2D top-down walking animation stop and revert to the idle animation while continuing to face in the same direction as the previous movement.

For example, when I go up then stop, my character should continue to look up. If I go down, it should continue to look down.

I use lastmoveX and lastmoveY floats for idle and for walking I use moveX and moveY floats. moveX and moveY change when I move with the joystick, but lastmoveX and lastmoveY do not change, and I don't know how to fix this.

Here is my code:

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

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D myRB;
    private Animator myAnim;
    public Joystick joystick;
    public MoveByTouch controller;

  

    [SerializeField]
    private float speed;

    // Use this for initialization
    void Start ()
    {
        myRB = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();

    }
    
    // Update is called once per frame
    void Update ()
    {
        myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

        myAnim.SetFloat("moveX", myRB.velocity.x);
        myAnim.SetFloat("moveY", myRB.velocity.y);

        if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
        {
            myAnim.SetFloat("lastMoveX", joystick.Horizontal);
            myAnim.SetFloat("lastMoveY", joystick.Vertical);
        }

       
    }
}
Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

2D TopDown game Idle&face correct Maintaining facing direction for mobile problemat the end of a movement

Hello guys i have problem about sth. II want to make my top-down walking animation stop and revert to the idle animation while continuing to face in the same way fordirection as the previous movement.

For example, when ıI go up then stop, my character will continuesshould continue to look up if i. If I go down, it will continuesshould continue to look down but it will be for mobile platform I.

I use lastmoveXlastmoveX and lastmoveYlastmoveY floats for idle and for walking moveXI use moveX and moveYmoveY floats moveY. moveX and moveY changingmoveY change when iI move with the joystick, but lastmoveXlastmoveX and lastmoveYlastmoveY do not changing please helpchange, and I don't know how to fix this. there

Here is my code:

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

public class PlayerController : MonoBehaviour { private Rigidbody2D myRB; private Animator myAnim; public Joystick joystick; public MoveByTouch controller;

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

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D myRB;
    private Animator myAnim;
    public Joystick joystick;
    public MoveByTouch controller;

  

    [SerializeField]
    private float speed;

    // Use this for initialization
    void Start ()
    {
        myRB = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();

    }
    
    // Update is called once per frame
    void Update ()
    {
        myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

        myAnim.SetFloat("moveX", myRB.velocity.x);
        myAnim.SetFloat("moveY", myRB.velocity.y);

        if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
        {
            myAnim.SetFloat("lastMoveX", joystick.Horizontal);
            myAnim.SetFloat("lastMoveY", joystick.Vertical);
        } 

       
    }
}

}

2D TopDown game Idle&face correct direction for mobile problem

Hello guys i have problem about sth. I want to make my animation stop in same way for example when ı go up then stop my character will continues to look up if i go down it will continues to look down but it will be for mobile platform I use lastmoveX and lastmoveY floats for idle and for walking moveX and moveY floats moveY and moveY changing when i move with joystick but lastmoveX and lastmoveY not changing please help. there is my code:

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

public class PlayerController : MonoBehaviour { private Rigidbody2D myRB; private Animator myAnim; public Joystick joystick; public MoveByTouch controller;

[SerializeField]
private float speed;

// Use this for initialization
void Start ()
{
    myRB = GetComponent<Rigidbody2D>();
    myAnim = GetComponent<Animator>();

}

// Update is called once per frame
void Update ()
{
    myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

    myAnim.SetFloat("moveX", myRB.velocity.x);
    myAnim.SetFloat("moveY", myRB.velocity.y);

    if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
    {
        myAnim.SetFloat("lastMoveX", joystick.Horizontal);
        myAnim.SetFloat("lastMoveY", joystick.Vertical);
    }

   
}

}

Maintaining facing direction at the end of a movement

I want to make my top-down walking animation stop and revert to the idle animation while continuing to face in the same direction as the previous movement.

For example, when I go up then stop, my character should continue to look up. If I go down, it should continue to look down.

I use lastmoveX and lastmoveY floats for idle and for walking I use moveX and moveY floats. moveX and moveY change when I move with the joystick, but lastmoveX and lastmoveY do not change, and I don't know how to fix this.

Here is my code:

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

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D myRB;
    private Animator myAnim;
    public Joystick joystick;
    public MoveByTouch controller;

  

    [SerializeField]
    private float speed;

    // Use this for initialization
    void Start ()
    {
        myRB = GetComponent<Rigidbody2D>();
        myAnim = GetComponent<Animator>();

    }
    
    // Update is called once per frame
    void Update ()
    {
        myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

        myAnim.SetFloat("moveX", myRB.velocity.x);
        myAnim.SetFloat("moveY", myRB.velocity.y);

        if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
        {
            myAnim.SetFloat("lastMoveX", joystick.Horizontal);
            myAnim.SetFloat("lastMoveY", joystick.Vertical);
        } 

       
    }
}
Source Link

2D TopDown game Idle&face correct direction for mobile problem

Hello guys i have problem about sth. I want to make my animation stop in same way for example when ı go up then stop my character will continues to look up if i go down it will continues to look down but it will be for mobile platform I use lastmoveX and lastmoveY floats for idle and for walking moveX and moveY floats moveY and moveY changing when i move with joystick but lastmoveX and lastmoveY not changing please help. there is my code:

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

public class PlayerController : MonoBehaviour { private Rigidbody2D myRB; private Animator myAnim; public Joystick joystick; public MoveByTouch controller;

[SerializeField]
private float speed;

// Use this for initialization
void Start ()
{
    myRB = GetComponent<Rigidbody2D>();
    myAnim = GetComponent<Animator>();

}

// Update is called once per frame
void Update ()
{
    myRB.velocity = new Vector2(joystick.Horizontal, joystick.Vertical) * speed * Time.deltaTime;

    myAnim.SetFloat("moveX", myRB.velocity.x);
    myAnim.SetFloat("moveY", myRB.velocity.y);

    if(joystick.Horizontal == 1 || joystick.Horizontal == -1 || joystick.Vertical == 1 || joystick.Vertical == -1)
    {
        myAnim.SetFloat("lastMoveX", joystick.Horizontal);
        myAnim.SetFloat("lastMoveY", joystick.Vertical);
    }

   
}

}