- Home /
Problem with connecting between the Walk mode and Idle mode, they are mix
Hello guys
I'm trying to make connection between Animation and the player and this is my script for the players movement
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float maxSpeed = 3;
public float speed= 50f;
public float jumpPower= 150f;
public bool grounded;
private Rigidbody2D rb2d;
private Animator animator;
void Start ()
{
rb2d = gameObject.GetComponent<Rigidbody2D> ();
animator = gameObject.GetComponent<Animator> ();
}
void Update ()
{
animator.SetBool ( "Grounded",grounded);
animator.SetFloat ("Speed",Mathf.Abs(Input.GetAxis("Horizontal")));
if (Input.GetAxis ("Horizontal") < -0.1f)
{
transform.localScale = new Vector3 (-12, 10, 1);
}
if (Input.GetAxis ("Horizontal") > 0.1f)
{
transform.localScale = new Vector3 (12, 10, 1);
}
}
void FixedUpdate()
{
float h = Input.GetAxis ("Horizontal");
//Moving the player
rb2d.AddForce((Vector2.right * speed)* h);
//Limiting speed of the player
if(rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2 (-maxSpeed, rb2d.velocity.y);
}
}
}
whats wrong with this? why my player mix with the idle mode and with the walk mode? please help :D
Comment
Your answer
Follow this Question
Related Questions
Strange animation behaviour trying to implement hover functionality 1 Answer
2D animation diferent right and left 0 Answers
Rare problem to moving an object using script+animation 0 Answers
Sebastian Lague Character Creation Tutorial animations not being triggered 0 Answers
Trying to add value to a float in animator each time an animation plays. 0 Answers