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)
Meaning the ray will always cast to the right of the object from where the mouse is.
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.