Question by
prototyped · May 13, 2016 at 08:31 PM ·
movementanimatorplatformer2.5dxaxis
running along the x Axis 2.5D
Im trying to make a 2.5D game so i want the player to run along the x axis, I can get him to run right but not left, I know i can use a transform function to flip him around but I cant even get him to "moon walk"
heres my code
using UnityEngine;
using System.Collections;
public class controller_and_anim : MonoBehaviour {
public Animator anim;
public Rigidbody rbody;
private float inputH;
private float inputV;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
rbody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
inputH = Input.GetAxis ("Horizontal");
inputV = Input.GetAxis ("Vertical");
anim.SetFloat ("inputH", inputH);
anim.SetFloat ("inputV", inputV);
float moveX = inputH * 100f * Time.deltaTime;
if (0 < moveX && moveX < 1.1f) {
rbody.velocity = new Vector2 (moveX, GetComponent<Rigidbody> ().velocity.y);
}
if (0 < moveX && moveX < -1.1f) {
rbody.velocity = new Vector2 (-moveX, GetComponent<Rigidbody> ().velocity.y);
}
}
}
`heres what I tried to do in the animator
attempt.png
(108.8 kB)
Comment
Answer by FortisVenaliter · May 13, 2016 at 08:40 PM
Your problem is here:
if (0 < moveX && moveX < 1.1f) {
rbody.velocity = new Vector2 (moveX, GetComponent<Rigidbody> ().velocity.y);
}
if (0 < moveX && moveX < -1.1f) {
rbody.velocity = new Vector2 (-moveX, GetComponent<Rigidbody> ().velocity.y);
}
In both of those, the first part is checking if moveX is more than zero. So, neither will trigger if it's less than zero.
okay that got him sliding back but why isnt he doing the forward run animation while moving back?