I’m sure I’m missing something simple, but my boxcast movement is causing the box to jitter when it hits a wall. It uses the skin to keep the collider from actually making contact with the wall. In this case I have the size at (1,1), this skin at .2, and the move at .001.
using UnityEngine;
using System.Collections;
public class TempScript : MonoBehaviour
{
public Vector2 size;
public float skin;
public float move;
void Update()
{
RaycastHit2D hit = Physics2D.BoxCast(transform.position, size, 0f, Vector2.up, move + skin);
if (hit.collider != null)
{
transform.Translate(hit.centroid - (Vector2)transform.position - new Vector2(0f, skin));
}
else
transform.Translate(new Vector2(0f, move));
}
private void OnDrawGizmosSelected()
{
//draw the collider box
Gizmos.color = Color.green;
Gizmos.DrawWireCube(transform.position, (Vector3)size);
//draw the collider box
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position, (Vector3)size + new Vector3(skin, skin, 0f) * 2f);
}
}
This is what it is supposed to look like
And this is what it looks like

The bottom position it keeps jumping to is the correct position.
