Top Down Animation/flipping
hy everyone i new of unity so he my question it seems stupid sorry:) I started to work on a top down game. And i have 2 problem the one is when start the Animation start the idle and animation walk together. The second proble is when the character move up,down.left,right the animation don't change yhe moviment of the face.
this is controller
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class Playercontroller2D : MonoBehaviour
{
public float moveForce = 25;
Rigidbody2D myBody;
AnimatoreControl myAnim;
void Start ()
{
myBody = this.GetComponent<Rigidbody2D>();
myAnim = AnimatoreControl.instancer;
}
void FixedUpdate ()
{
Vector2 moveVec = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"), CrossPlatformInputManager.GetAxis("Vertical"))* moveForce;
myAnim.UpdateSpeed(moveForce);
myBody.AddForce(moveVec);
}
}
ad this my animation
using UnityEngine;
using System.Collections;
public class AnimatoreControl : MonoBehaviour {
public static AnimatoreControl instancer;
Transform myTransf;
Animator myAnim;
Vector3 artScaleCacher;
void Start ()
{
myTransf = this.transform;
myAnim = this.gameObject.GetComponent<Animator>();
instancer = this;
artScaleCacher = myTransf.localScale;
}
void FlipArt (float currentSpeed)
{
if ((currentSpeed < 0 && artScaleCacher.x == 1 ) ||
(currentSpeed > 0 && artScaleCacher.x == -1))
{
artScaleCacher.x *= -1;
myTransf.localScale = artScaleCacher;
}
}
public void UpdateSpeed (float currentSpeed)
{
myAnim.SetFloat("Speed", currentSpeed);
FlipArt(currentSpeed);
}
}
I hope someone can help me o advise some tutorial.
Your answer
Follow this Question
Related Questions
How do I add running and animations to my FPS controller script? 0 Answers
help to connect two objects together 0 Answers
Animation with different behaviors for different directions. 1 Answer
please help me, i'm creating a first person game, but my script is incomplete and i can't crouch 0 Answers
Ghange the code of the character controller in 3d platformer game kit 0 Answers