I have been watching the 2D Character Controllers tutorial. I set up everything like he did using my own sprites. I ran into a problem when adding jump. He adds a game object to detect ground which worked okay at first. I got the check mark when on the ground and when I fell, it went away. So I tried setting up jump with a blend tree to smooth animation. When I did this, some how player no longer detected the ground. Player would also jump with out me hitting space bar. He would also jump forever. So I changed the code and just made the animation normal. After that everything worked fine. This was at midnight last night. Saved closed everything and went to bed. When I got up everything I did was still the same. But When I hit play the player jumps again without hitting space bar forever. very strange and frustrating any help would be appreciated.
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour
{
public float jumpforce =700f;
public float maxSpeed = 10f;
bool faceRight = true;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate ()
{
anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && ! faceRight)
flip ();
else if (move < 0 && faceRight)
flip ();
}
void Update()
{
if( Input.GetKeyDown(KeyCode.Space));
{
rigidbody2D.AddForce(new Vector2( 0, jumpforce));
}
}
void flip ()
{
faceRight = !faceRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}