Getting vector which is pointing to the right/left of a direction vector?

If I have a vector such as (0,0,1) and I get its ‘right’ equivalent I should get something like (1,0,0), its left would be (-1,0,0), this is just the simplest case there may be more complex scenarios such as (0.2, 0.3, 0.5), so on and so forth.

Any ideas?

In a 2D space - Vector2, or Vector3 with one coordinate fixed at 0 - you can get the right and left vectors with simple transformations:

  // original vector in the xz plane (y = 0):
  var forward: Vector3 = Vector3(0.5, 0.0, 0.8);
  // transformed vectors right and left:
  var right = Vector3(forward.z, forward.y, -forward.x);
  var left = -right;

For a full 3D vector, however, there’s no predefined left/right directions - you must set some reference, usually the up direction. Having the up direction, you can calculate the right and left vectors using a cross product:

  // original vector:
  var forward: Vector3 = Vector3(0.5, 0.7, 0.8);
  // up direction:
  var up: Vector3 = Vector3(0.0, 1.0, 0.0);
  // find right vector:
  var right = Vector3.Cross(forward.normalized, up.normalized);
  var left = -right;

NOTE: I never remember the correct order of the Cross parameters; if the right vector is pointing to the left, just swap the parameters.

Use the vector cross-product:

In the first case you would obtain it like this: bnrm = (0,0,1) x (0,1,0)

(although I am not sure if the sign would be right.) :smiley: