- Home /
Player Don´t Jump
I followed The 2d Tutorial her in Unity...but my Player still can´t jump...here is the code
using UnityEngine;
using System.Collections;
public class MrCorkCharacterController : MonoBehaviour
{
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
bool doubleJump = false;
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool("Ground", grounded);
if (grounded)
doubleJump = false;
anim.SetFloat ("vSpeed", rigidbody2D.velocity.y);
if (!grounded)
return;
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()
{
if((grounded || !doubleJump) && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("Ground", false);
rigidbody2D.AddForce(new Vector2(0, jumpForce));
if (!doubleJump && !grounded)
doubleJump = true;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Comment
Your answer
Follow this Question
Related Questions
Why does my 2d player stick to the floor when he lands? 0 Answers
Unity 2D Top Down Jump 1 Answer
Problem with joints 2 Answers
Drag and jump mechanics? 2 Answers
My player wont jump (2d game) 1 Answer