Hello!
Im trying to find a way to visualize, and Edit the Physics2D.BoxCast from the Editor.
I wrote the methods below to visualize the BoxCast, and edit in the editor:
public Rect Box;
private void OnDrawGizmos()
{
Gizmos.color = Color.magenta;
Gizmos.matrix = Matrix4x4.TRS(transform.position + (Vector3) Box.position, transform.rotation, Vector3.one);
Gizmos.DrawWireCube(Vector2.zero, Box.size);
}
// Update is called once per frame
private void Update()
{
var hits = Physics2D.BoxCastAll(transform.position + (Vector3) Box.position, Box.size,
transform.eulerAngles.z, Vector2.right, 0, 1 << LayerMask.NameToLayer("Player"));
foreach (var hit in hits)
Debug.Log(hit.transform.name);
}
It works fine, but when I edit the object rotation I get this problem:
I can fix it easily, putting just transform.position, instead of transform.position + (Vector3)Box.Position.
But if I do it, i will not be able to edit the Raycast position.
So, how I can solve this?