- Home /
2D player stuck between BoxColliders
To create a terraria-clone, i'm procedurally instantiating multiple sprites/gameobjects with a boxcollider2d attached to them, so every cube has its own 2d boxcollider. The problem is that VERY randomly my character gets stuck between two boxcolliders, it really happens randomly but not that rarely, every 10/20/30 seconds or so of walking may happen
Player moves throught rigidbody.velocity.x and no gravityscale gets changed, here's the code for the "D" key used to move it right
if(Input.GetKey(KeyCode.D))
rigidbody2D.velocity = new Vector2(4f, rigidbody2D.velocity.y);
if (Input.GetKeyDown(KeyCode.D))
{
if (transform.localScale.x < 0) //used to change the direction that player is facing
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
//setting the animation to true
PlayerAnim.SetBool("Running", true);
}
if (Input.GetKeyUp(KeyCode.D))
{
PlayerAnim.SetBool("Running", false);
//stopping the animation and setting the velocity to zero
rigidbody2D.velocity = new Vector2(0f, rigidbody2D.velocity.y);
}
Edit : yes, every square is instantiated in a pixel perfect fashion, 1f x 1f is the dimension of each one to keep better track of coordinates
Answer by Sonicbulletwolf · Sep 27, 2014 at 08:36 PM
Maybe you should make the Boxcollider of the play a little less longer
I tried already to make overlapping colliders and shorter ones. Still getting the issue