something like PerpendicularDotProduct

//AxB = (AyBz-Azby, AzBx-AxBz, AxBy-AyBx)

is there a build in function of Vector3 or something else bringing me the perpendicular Vector?

would be nice to see such function in upcoming unity releases.

greets

Maybe someone has a better way to get it.

static private var tempVec : Vector3 = Vector3.up; 
var target : Transform;
var speed=10;




function awake ()
{

//turnMe(target.position, transform.position, transform.forward); 

}



function turnMe(apos : Vector3, bpos : Vector3, B : Vector3, turnSpeed : float) {
   tA.x = apos.x - bpos.x;
   tA.y = apos.y - bpos.y;
   tA.z = apos.z - bpos.z;
   //AxB = (Ay*Bz-Az*by, Az*Bx-Ax*Bz, Ax*By-Ay*Bx) 
   var D1z : float = tA.x*B.z-tA.z*B.x;
   var D1y : float = tA.z*B.x-tA.x*B.z;
   
   
     if (D1y >= 0) {
      tempVec.x = turnSpeed*Time.deltaTime;
      transform.Rotate(tempVec, Space.World);
      return true; 
   } else {
      tempVec.x = -turnSpeed*Time.deltaTime;
      transform.Rotate(tempVec, Space.World);
      return false; 
   }
   

    
   
   
}
var rotationDirection : boolean = false;
 var fastRotateMode : boolean = true;
 var slowRotateCount : int = 0;
 var rotateSpeedSlow=10;
 var rotateSpeedFast=10;
 
 var tA : Vector3;
function FixedUpdate() {
   var ret : boolean = turnMe(target.position, transform.position, transform.forward, fastRotateMode ? rotateSpeedFast : rotateSpeedSlow);
   if (fastRotateMode) {
      if (ret != rotationDirection) {
         fastRotateMode = false;
      }
   } else {
      if (ret == rotationDirection) {
         if (slowRotateCount > 5) {
            fastRotateMode = true;
            slowRotateCount = 0;
         }
         slowRotateCount++;
      }
   }
   rotationDirection = ret;
}

Sadly, programming languages build in math functions rarely get more complex than basic trigonomentry, Unity being no exeption.
Remember though, that you can always make your own class with static functions for whatever math functions you usually use and then carry that class around the diffrent project you make.
I usually do this.

EDIT:
And no, I don’t think there’s any better way to do it :confused:

  • Chris

I have never heard the term perpendicular dot product before, but from your description it appears that you’re looking for the cross product of two vectors. In Unity, you can calculate the cross product using Vector3.Cross(Vector3, Vector3).

Note also that you can calculate your vector tA by simply writing tA = apos - bpos; (although you may want to write bpos - apos if you want the vector from a to b :P).