//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;
}