I'm trying to figure out how I can best offset a direction when raycasting.
So let's say I have an object and I want to cast a ray from my mouse position to said object, that's easily done with (for example):
// "obj" being the transform of the object I'm raycasting to.
Vector2 mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 dir = (Vector2)obj.position - mPosition;
Debug.DrawRay(mPosition, dir, Color.green);
But what if I want the direction to always be slightly offset to the right of the object from the mouse position? And I mean not just to the right of the object itself, but to the right from where the mouse is.
I hope I'm making any sense. Here are some pictures to try and make it a little more clear: (Pretend the line is the ray and the circle is the object)
I want to offset the ray so that when my mouse is under the circle, it goes to the right of it, like this:
However, when I move my mouse to the left of the object, the ray should instead go like this:
Meaning the ray will always cast to the right of the object from where the mouse is.
The reason I want to do this is because I'm trying to raycast to the corners of objects, but also see what's past them:
I need to use offset rays to just barely miss the corners and allow them to continue on and see if there's a wall behind them like on the picture above. I'm offsetting my rays in the picture above, but the way I'm doing it isn't the best and I'm trying to find the proper way of doing it.