- Home /
Question by
DerSeb · Jun 08, 2015 at 10:14 AM ·
playerjumpplayer movementkey
Player cannot jump
Hey Guys. I need help because my player doesnt want to jump. Could you please look after the skript? Thanks.
using UnityEngine; using System.Collections;
public class PlayerMove : MonoBehaviour {
public float maxSpeed = 4;
public float jumpForce = 550;
public Transform groundCheck;
public bool lookingRight = true;
public LayerMask whatIsGround;
private Rigidbody2D rb2d;
private Animator anim;
private bool IsGrounded = true;
private bool Jump = false;
void Start () {
rb2d = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Upate() {
if (Input.GetButtonDown ("Jump") && IsGrounded) {
Jump = true;
}
}
void FixedUpdate() {
float hor = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (hor));
rb2d.velocity = new Vector2 (hor * maxSpeed, rb2d.velocity.y);
IsGrounded = Physics2D.OverlapCircle (groundCheck.position, 0.15F, whatIsGround);
anim.SetBool("IsGrounded", IsGrounded);
if ((hor > 0 && !lookingRight) || (hor < 0 && lookingRight))
Flip ();
if (Jump) {
rb2d.AddForce(new Vector2 (0,jumpForce));
Jump = false;
}
}
public void Flip() {
lookingRight = !lookingRight;
Vector3 myScale = transform.localScale;
myScale.x *= -1;
transform.localScale = myScale;
}
}
Comment
Your 'Upate' function won't be getting called, it should be 'Update'.
But i wrote an 'Update' and an 'FixedUpdate' function and it didnt work
No no, he literally means your Update function will not be called by Unity. You typed Upate().. not Update()..
So, if you have fixed your misspelling the word Update, and the problem is still occurring then my best guess would be your layers are not setup properly for the player to be grounded.