i have just watched the 2D Character Controllers video tutorial
and i haven’t had problems working through it until it got to the jump part, my character doesn’t jump when i click space, but the “vspeed” is working because if i walk off the edge of my ground the “vspeed” changes, showing my animation. i don’t know if you know what im talking about so ill just show you the script and hopefully someone can tell me the problem.
**using UnityEngine;
using System.Collections;
public class charactercontrol : MonoBehaviour {
public float maxspeed = 2f;
bool facingright = true;
Animator anim;
bool grounded = false;
public Transform groundcheck;
float groundRadius = 0.2f;
public LayerMask whatisground;
public float jumpforce = 700f;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate ()
{
grounded = Physics2D.OverlapCircle (groundcheck.position, groundRadius, whatisground);
anim.SetBool ("Ground", grounded);
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 &&!facingright)
Flip();
else if (move < 0 && facingright)
Flip ();
}
void update()
{
//float jump = Input.GetAxis ("Vertical");
//anim.SetFloat ("jumpforce", Mathf.Abs (jump));
if (grounded && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("Ground", false);
rigidbody2D.AddForce(new Vector2 (0, jumpforce));
}
}
void Flip()
{
facingright = !facingright;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}**
thanks.