- Home /
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); } }
Your answer
Follow this Question
Related Questions
How to make a moving enemy shoot at the player rather than the player's spawn? 1 Answer
Beginner trying to stop movement function and collision on death ? 0 Answers
Flip Player, Not the Player's Child. 3 Answers
How to instantiate tiles based on a 2D Array into a Platform Game? 1 Answer
Load time of 2D TileMaps 0 Answers