Raycast2D and origin position Offset

Hi,

I am raycasting from a gameObject that constantly looks for a target. I want to Raycast with an offset from the objects transform.position so i avoid hitting my own colliders.

Here is what I want to do:

37919-raycast.png

Vector2 dir = target.transform.position - transform.position;
RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, rayDistance);

I want to raycast from “Desired offset” in the image.

Also, the gameObject’s rotation or direction dont matter because it’s independent of the raycasting.

RaycastHit2D hit = Physics2D.Raycast(transform.position + dir.normalized * distanceToOffset, dir, rayDistance);