first of all. im making a 2d pixel game (with ragepixel). its very basic.
so, i’m heading right to the point.
my character moves the way i want it to, but the animations dont.
when holding down left or right arrow key it does the “WALK” animation.
and when im holding down both left and right the character should stop (witch it does) and then play the “STAND” animation.
the thing is when im walking, lets say right (holding down right arrow key), and then press the left arrow key it stops but continues the “WALK” animation. and then when im releasing the left arrow it moves right but plays the “STAND” animation.
I have no clue at all what to write in the script to “get rid of” the problem.
If you know the problem, could you explain whats wrong?
Thanks in advance!
Here is my Script:
using UnityEngine;
using System.Collections;
public class pmovetest : MonoBehaviour {
IRagePixel ragepixel;
private float walkSpeed = 10f;
// Use this for initialization
void Start () {
ragepixel = GetComponent<RagePixelSprite>();
ragepixel.SetSprite ("STAND");
ragepixel.PlayNamedAnimation ("STAND");
}
// Update is called once per frame
void Update () {
var inputLeft = Input.GetKey (KeyCode.LeftArrow);
var inputLeftDown = Input.GetKeyDown (KeyCode.LeftArrow);
var inputLeftUp = Input.GetKeyUp (KeyCode.LeftArrow);
var inputRight = Input.GetKey (KeyCode.RightArrow);
var inputRightDown = Input.GetKeyDown (KeyCode.RightArrow);
var inputRightUp = Input.GetKeyUp (KeyCode.RightArrow);
Vector3 moveDirection = new Vector3();
// Gå vänster
if (inputLeft !inputRight)
{
moveDirection = new Vector3(-1f, 0f, 0f);
if (inputLeftDown !inputRightDown)
{
ragepixel.SetSprite("WALK");
ragepixel.SetHorizontalFlip(true);
ragepixel.PlayNamedAnimation("WALK");
}
}
// Gå höger
if (inputRight !inputLeft)
{
moveDirection = new Vector3(1f, 0f, 0f);
if (inputRightDown !inputLeftDown)
{
ragepixel.SetSprite("WALK");
ragepixel.SetHorizontalFlip(false);
ragepixel.PlayNamedAnimation("WALK");
}
}
if (inputLeftUp || inputRightUp)
{
ragepixel.SetSprite("STAND");
ragepixel.PlayNamedAnimation("STAND");
}
transform.Translate (moveDirection * Time.deltaTime * walkSpeed);
}
}
thanks, that solves the problem. but of course there’s a new one… ^^
when simply walking left or right by holding down key left OR right and then release the key, the character continues the WALK animation, when it should go to STAND animation.
and when im holding down left AND right key it changes to the STAND sprite but wont animate.
im sorry for my stupidity but im still learning the basics!
just replace the print(…); with your ragepixel.whatever()
ah and i see you are using C#
replace var input:int; with private int input;
and function Update () with void Update ()
the rest stays the same on first looks.