Make box face a point

edited November 2014 in How To...

Pretty much what title says. I have a bunch of boxes and I want them to face a point(x, y, z) or mouse. How do I achieve that? I've been try with atan2 function, but i only got it working for 2nd quadrant and 3rd quadrant. Here is my function:

float[] atan3(float x, float y, float z) {    
  return new float[]{ 
        (float)Math.atan2(y - this.y, x - this.x) , // z axis 
        (float)Math.atan2(z - this.z, x - this.x)  // y axis                        

It accepts x, y, z of a point to face.


  • Not a solution, just an alternative to your method above: :ar!

    PVector atan3(float xx, float yy, float zz) {
      return new PVector(atan2(yy-y, xx-x), atan2(zz-z, xx-x));
  • Try this trick, perhaps:

      float angle = atan2(y2- y1, x2- x1);
      if (angle < 0)
        angle += TWO_PI;
Sign In or Register to comment.