Hello,
I am trying to get the direction of the vector perpendicular to the direction vector of 2 points(A,B) illustrated below. I understand a cross product requires a reference vector like transform.right to work, but I get weird behavior when the direction(dir) vector is equal to the reference vector transform.right: the rigidbody2d I am moving with it just wobbles back and forth.
P.S. using the rigidbodies transform.right would be good, but it’s always rotating, so that can’t work.
Any physics-related suggestions are appreciated!
void Rotate(Rigidbody2D rb)
{
Vector3 dir = rb.transform.position - transform.position;
dir.Normalize();
Vector3 side = Vector3.Cross(dir, -transform.right);
Vector3 cross = Vector3.Cross(dir, side);
rb.AddForce(cross.normalized * speed);
}