Player doesn't move
i'm making a 2d platform game and now the playr just don't move, also he is not affected by gravity here is my player script: using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public Animator Anim;
//Animações
public bool andar;
public bool correr;
public bool agachado;
public bool pulando;
public bool dashando;
public bool pulando2;
public bool atirando;
//Movimento
public float speed;
public float jump;
public float moveVelocity;
public float dash;
public static bool direita;
//Double Jump
public bool djump;
public int cjump = 0;
//Grounded Vars
bool grounded = true;
//Tiro
public bool atirar;
public bool atirendo;
public Vector3 tiro;
public GameObject tiroo;
GameObject tirooclone;
//Knockback nessa porra
public float knockback;
public float knockbacklength;
public float knockbackcount;
public bool knockfromright;
//X e Y atirando parado
public float tpx;
public float tpy;
//Limitadores
public float tdash;
public float vida;
//Espada
public bool atacando;
public bool invencivel;
//Chegando
public bool achao;
public bool chegando;
public bool chegou;
public float contador;
void Start ()
{
tdash = 100f;
vida = 1f;
achao = true;
contador = 0.3f;
direita = true;
}
void Update ()
{
//if ((achao == false) && (chegou == true))
//{
//No Chão
if (grounded == false)
{
djump = true;
}
if (grounded == true)
{
cjump = 0;
djump = false;
pulando = false;
pulando2 = false;
}
//Pulando
if (Input.GetKeyDown (KeyCode.Z) && (agachado == false) && (knockbackcount <= 0))
{
if (grounded)
{
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, jump, GetComponent<Rigidbody> ().velocity.z);
pulando = true;
correr = false;
andar = false;
dashando = false;
}
}
moveVelocity = 0;
//Andar Direita e Esquerda
if (Input.GetKey (KeyCode.LeftArrow) && (agachado == false) && (knockbackcount <= 0))
{
andar = false;
direita = false;
moveVelocity = -speed;
andar = true;
transform.localScale = new Vector3 (-7, 7, 7);
}
if (Input.GetKey (KeyCode.RightArrow) && (agachado == false) && (knockbackcount <= 0))
{
direita = true;
andar = true;
moveVelocity = speed;
andar = true;
transform.localScale = new Vector3 (7, 7, 7);
}
if (Input.GetKeyUp (KeyCode.LeftArrow) && (agachado == false) && (knockbackcount <= 0))
{
andar = false;
}
if (Input.GetKey (KeyCode.DownArrow) && (knockbackcount <= 0))
{
agachado = true;
andar = false;
correr = false;
pulando = false;
dashando = false;
}
if (Input.GetKeyUp (KeyCode.DownArrow))
{
agachado = false;
}
if (Input.GetKey (KeyCode.DownArrow) && (Input.GetKeyDown (KeyCode.RightArrow)) && (knockbackcount <= 0))
{
direita = true;
transform.localScale = new Vector3 (7, 7, 7);
}
if (Input.GetKey (KeyCode.DownArrow) && (Input.GetKeyDown (KeyCode.LeftArrow)) && (knockbackcount <= 0))
{
direita = false;
transform.localScale = new Vector3 (-7, 7, 7);
}
if (Input.GetKeyUp (KeyCode.RightArrow) && (agachado == false) && (knockbackcount <= 0))
{
andar = false;
}
//Correr
if (Input.GetKey (KeyCode.LeftArrow) && Input.GetKey (KeyCode.LeftShift) && (agachado == false) && (dashando == false) && (pulando == false) && (tdash > 0) && (knockbackcount <= 0))
{
direita = false;
moveVelocity = -speed * 2;
correr = true;
andar = false;
transform.localScale = new Vector3 (-7, 7, 7);
tdash -= 1.5f;
}
if (Input.GetKey (KeyCode.RightArrow) && (Input.GetKey (KeyCode.LeftShift)) && (agachado == false) && (dashando == false) && (pulando == false) && (tdash > 0) && (knockbackcount <= 0))
{
direita = true;
moveVelocity = speed * 2;
correr = true;
andar = false;
transform.localScale = new Vector3 (7, 7, 7);
tdash -= 1.5f;
}
if (Input.GetKeyUp (KeyCode.LeftShift))
{
correr = false;
}
if (knockbackcount <= 0)
{
GetComponent<Rigidbody> ().velocity = new Vector3 (moveVelocity, GetComponent<Rigidbody> ().velocity.y, GetComponent <Rigidbody> ().velocity.z);
}
else
{
if (knockfromright == true)
GetComponent<Rigidbody> ().velocity = new Vector3 (-knockback, knockback, GetComponent<Rigidbody> ().velocity.z);
if (knockfromright == false)
GetComponent<Rigidbody> ().velocity = new Vector3 (knockback, knockback, GetComponent<Rigidbody> ().velocity.z);
knockbackcount -= Time.deltaTime;
}
//Pulo Duplo
if (Input.GetKeyDown (KeyCode.Z) && cjump == 0 && agachado == false)
{
if (djump)
{
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, jump, GetComponent<Rigidbody> ().velocity.z);
pulando2 = true;
}
}
if (Input.GetKeyDown (KeyCode.Z) && djump == true)
{
cjump = cjump + 1;
}
//Dash
if ((dashando == false) && (correr == false))
{
tdash += 1.5f;
}
if (tdash >= 100)
{
tdash = 100;
}
if ((dashando == true) && tdash <= 5)
{
tdash = 5;
dashando = false;
speed = 6;
GetComponent<Rigidbody> ().velocity = new Vector3(GetComponent<Rigidbody> ().velocity.x, -15, GetComponent<Rigidbody> ().velocity.z);
}
else if (tdash <= 0)
{
tdash = 0;
dashando = false;
speed = 6;
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, -15, GetComponent<Rigidbody> ().velocity.z);
}
if (Input.GetKey (KeyCode.LeftArrow) && (Input.GetKey (KeyCode.D)))
{
moveVelocity = -speed * 2;
dashando = true;
transform.localScale = new Vector3 (-7, 7, 7);
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, dash, GetComponent<Rigidbody> ().velocity.z);
tdash -= 5;
}
if (Input.GetKey (KeyCode.RightArrow) && (Input.GetKey (KeyCode.D)))
{
moveVelocity = speed * 2;
dashando = true;
transform.localScale = new Vector3 (7, 7, 7);
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, dash, GetComponent<Rigidbody> ().velocity.z);
tdash -= 5;
}
if (Input.GetKey (KeyCode.RightArrow) && (Input.GetKey (KeyCode.D) && (tdash <= 0)))
{
moveVelocity = speed;
dashando = false;
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, -15, GetComponent<Rigidbody> ().velocity.z);
}
if (Input.GetKey (KeyCode.LeftArrow) && (Input.GetKey (KeyCode.D) && (tdash <= 0)))
{
moveVelocity = speed;
dashando = false;
GetComponent<Rigidbody> ().velocity = new Vector3 (GetComponent<Rigidbody> ().velocity.x, -15, GetComponent<Rigidbody> ().velocity.z);
}
if (Input.GetKey (KeyCode.D) && (tdash > 0))
{
speed = 24;
}
if (Input.GetKeyUp (KeyCode.D))
{
dashando = false;
speed = 6;
}
if (Input.GetKeyUp (KeyCode.D) && (tdash <= 0))
{
dashando = false;
speed = 6;
}
if (Input.GetKeyUp (KeyCode.RightArrow) || (Input.GetKeyUp (KeyCode.LeftArrow)))
{
dashando = false;
}
if (dashando == true && (Input.GetKey (KeyCode.UpArrow)))
{
dash = 1;
}
if (dashando == true && (Input.GetKeyUp (KeyCode.UpArrow)))
{
dash = 0;
}
if (dashando == false)
{
dash = 0;
}
//Tiro
if (Input.GetKeyDown (KeyCode.X))
{
Atirar ();
atirando = true;
}
if (Input.GetKeyUp (KeyCode.X))
{
atirando = false;
}
if (direita == true)
{
tpx = 0.7f;
} else {
tpx = -0.7f;
}
if (agachado == true)
{
tpy = 0.95f;
} else {
tpy = 1.3f;
}
//Espada
if (Input.GetKeyDown (KeyCode.A))
{
atacando = true;
}
if (Input.GetKeyUp (KeyCode.A))
{
atacando = false;
}
//Cheats
if (Input.GetKey (KeyCode.I))
{
tdash += 100;
dash = 5;
}
if (Input.GetKey (KeyCode.K))
{
tdash += 100;
dash = -5;
}
if (Input.GetKey (KeyCode.L))
{
tdash += 100;
}
//Vida
if (vida <= 0)
{
Destroy (gameObject);
}
//}
if ((chegando == true) && contador >= 0) {
contador -= Time.deltaTime;
}
else if (contador < 0)
{
chegou = true;
chegando = false;
}
tiro = new Vector3 (transform.position.x + tpx, transform.position.y + tpy, transform.position.z);
//Animações
Anim.SetBool("andando", andar);
Anim.SetBool("correndo", correr);
Anim.SetBool("agachado", agachado);
Anim.SetBool("pulando", pulando);
Anim.SetBool("dashando", dashando);
Anim.SetBool("pulando2", pulando2);
Anim.SetBool("atirando", atirando);
Anim.SetBool("atacando", atacando);
Anim.SetBool ("chegou", chegou);
Anim.SetBool ("chegando2", chegando);
}
//Checar o Ground
void OnTriggerEnter(Collider col)
{
if (col.name == "Ground")
{
grounded = true;
if (achao == true) {
achao = false;
chegando = true;
}
}
}
void OnTriggerExit2D()
{
grounded = false;
}
//Atirar
void Atirar()
{
tirooclone = Instantiate(tiroo, tiro, Quaternion.identity) as GameObject;
Destroy (tirooclone, 5);
}
}
as i'm brazillian most part of the variables are in portuguese, so if you don't know what it does just ask
Comment