Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by wiliamks · Jun 26, 2016 at 06:56 PM · movementplayermovemoving

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
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make better player movement 0 Answers

When friction on physic material 2d is at 0 my player slide 0 Answers

Cardboard and Navmesh: Problem with Player Movement 0 Answers

Change Camera's size relative to player's speed 0 Answers

Top Down Character - Face direction of movement? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges