• 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 /
avatar image
0
Question by TheDevilman · May 13 at 09:15 PM · player2d-platformershootingtilemapflipping

Player Flipping and Shot/Tilemap bugs

Well, I'm new to unity and I'm trying to make a simple platform, my player has the basic functions working but I found some bugs that I have no idea how they appeared and how to fix them.

The Bugs are: My bullet at a specific point on the map crosses the tilemap

Rotating the player makes it move 1 frame to the side and grab walls


Codes (I accept suggestions for new ones if they are better) :

  • Player Controller

       public Rigidbody2D theRB;
         public float moveSpeed;
         public float jumpForce;
         public Transform groundPoint;
         private bool isOnGround;
         public LayerMask whatIsGround;
         public Animator anim;
         public BulletController shotToFire;
         public Transform shotPoint;
         private bool canDoubleJump;
     
         
     
         // Start is called before the first frame update
         void Start()
         {
             
         }
     
         // Update is called once per frame
         void Update()
         {
             
     
             //Move sideways
             theRB.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, theRB.velocity.y);
     
             //handle Direction Change
             if(theRB.velocity.x< 0)
             {
                 transform.localScale = new Vector3(-1f, 1f, 1f);
             }   
             else if (theRB.velocity.x> 0)
             {
                 transform.localScale = Vector3.one;
             }
     
             
     
             //Ground if on Ground
             isOnGround = Physics2D.OverlapCircle(groundPoint.position, .2F, whatIsGround);
     
     
             //Jumping
             if (Input.GetButtonDown("Jump") && (isOnGround || canDoubleJump) )
             {
                 if (isOnGround)
                 {
                     canDoubleJump = true;
                 } else {
                     canDoubleJump = false;
                     anim.SetTrigger("doubleJump");
                 }
     
                 theRB.velocity = new Vector2(theRB.velocity.x, jumpForce);            
     
             }
     
     
             if(Input.GetButtonDown("Fire1"))
             {
                 Instantiate(shotToFire, shotPoint.position, shotPoint.rotation).moveDir = new Vector2(transform.localScale.x, 0f);
     
                 anim.SetTrigger("shotFired");
             }
     
             anim.SetBool("isOnGround", isOnGround);
             anim.SetFloat("speed", Mathf.Abs (theRB.velocity.x));
         }
     
     }
    
     
    
    
    

  • Bullet Controller

       public float bulletSpeed;
         public Rigidbody2D theRB;
         public Vector2 moveDir;
         public GameObject ImpactEffect;
     
         // Update is called once per frame
         void Update()
         {
             theRB.velocity = moveDir * bulletSpeed;
         }
     
         
         private void OnTriggerEnter2D(Collider2D other)
         {
             if(ImpactEffect != null)
             Instantiate(ImpactEffect, transform.position, Quaternion.identity);
     
             Destroy(gameObject);
     
         }
     
         
         private void OnBecameInvisible()
         {
             Destroy(gameObject);
         }
         
     }
     
    
    
    
    
    
    
    
    
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

183 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 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 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

Trouble with tilemaps as prefabs for 2D plattformer 1 Answer

2d Tilemaps, pass through some objects 1 Answer

Unity 2D On Player Flip change shooting direction? 1 Answer

shoot bullet on a moving gameobject 0 Answers

2D Platformer – changing the cursor position when facing left or right 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