I'm casting a raycast from the mouse cursor to a point. Then I would like to cast another almost identical raycast, with the only difference being that it should have a slight offset to the right.
I'm doing this in Unity2D, what's the best way to go on about this?
It has to take the mouse position into account, so that the direction it's casting to is offset to the right of the cursor's position.
Make a normal vector from this direction vector.
If your direction vector coordinates are v1(A; B) then your normal vector is vNormal(B; -A)
And now you offset your original start point (where the ray is heading from to its direction), by the following formula point += vNormal.normalized * OffsetValue;
, assuming this exists public float OffsetValue = 5.0f;
Some visuals: So, if we move your mousePos by the green line normalvector(the yellow line direction vector), we can shoot a ray like the purple line. Expected result:
Update:
Is this the result you want?
Because in this case, you offset the hitpoint the same way you would offset the mousePos, and then calculate a new direction for your ray Vector2 newDir = offsettedHitPoint - mousePos;