How can I add two Vector3 directions together?

I have a direction to my target object, which is in a Vector3 format. I want cast a number of rays, as offsets from this initial direction.

X is the object. D is the direction the player needs to travel in. A & C are other directions that I want to cast rays towards to check for impacts.

A    D    C
 \   |   /
  \  |  /
   \ | /
    [x]

I was trying to add an offset, such as Vector3.Right to the Direction and then normalise the result, however this only works if everything is oriented towards World Space.

So how can I convert and add a direction (Vector3.right) as an offset to an existing direction?

I’m fairly sure I just have World Space and Local Space directions mixed up but can’t see an easy way to convert between this with Vector3?

Have you looked at transform.right? This will be relative to the transforms current rotation

Vector3 heading = transform.forward;
Vector3 rightCheck = heading + (transform.right * .5f);
Vector3 leftCheck = heading - (transform.right * .5f);

rightCheck is C from your diagram, leftCheck is A. You may need to normalize the vector depending on what you’re doing exactly. Multiplying by .5f should give you a 22.5 degree angle, so adjust it as needed depending on the angle you want.

In your diagram, your Vector happens to be pointing directly up. In THIS case your can use Vector3.right and Vector3.left, to get those offsets you want to add.

However if your vector is at some arbitrary angle, you will need to use some kind of rotated version of Vector3.right and left. The important thing to note, it that those offset vectors need to be Perpendicular to your initial vector.

There are an infinite number of vectors that are perpendicular to a Vector3 (think; a disk of directions at the end of the vector). This is unlike a Vector2 you might draw on paper, which has only 1 perpendicular line.

I would probably use Vector3.Cross product to compute this vector, but this will require another Vector that will be perpendicular to BOTH. I think there is also shortcut like PerpVector= new Vector3(-vec.z,vec.x,vec.y); to get a perpendicular vector, but I’ve not tested that…