My Box Collider 2D is not working correctly on the Y axis
So my character is 32x32 pixels. However I have the green box on the Box Collider 2D sized and offset to his actual shape (he's roughly 21x14 pixels).
The collider reads fine on the X axis, but on the Y axis, he does not approach walls correctly. In the positive Y he cannot get close enough to the wall, and on the -Y axis he walks into the wall tile slightly. He does stop and collides, but a bit too late.
Answer by progamerpagan819 · Feb 03 at 05:33 PM
Can you give an Image for reference? If you having problems with collision you probably using "transform.Translate" this is not meant to be used with colliders you will need to use something with RigidBoby like playerRb.AddForce or playerRb.Moveposition.
Note that you will need to set the component to the playerRb first.
using UnityEngine;
public class MoveUsingRb : MonoBehaviour
{
private Rigidbody2D playerRb;
private float speed = 1f;
private void Start()
{
playerRb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
playerRb.AddForce(transform.right * speed * Time.deltaTime, ForceMode2D.Impulse);
}
}
Note that the RigidBody2D haves a Gravity component so if your game is top-down you will want to set that to 0 so the player doesn't start going down.
Your answer
![](https://koobas.hobune.stream/wayback/20220613052526im_/https://answers.unity.com/themes/thub/images/avi.jpg)