## isfacingpoint

Moderator
Posts: 916
Joined: 2002.10
Post: #1
// returns if unit is facing within a degrees of point
//angle that the object is facing, where to face, within how many degrees
//bob includes x and y positions and directions and other things if you want to assume
char isfacingpoint(OT *bob,float xpos,float ypos,int degrees)

any quick(or even non quick) ways to do this? It has been troubling my brain all afternoon
Jeff Binder
Unregistered

Post: #2
Perhaps something like this:

Code:
```//Warning! Untested! char isfacingpoint(OT *bob,float xpos,float ypos,int degrees) {   float xv = xpos - bob.x;   float yv = ypos - bob.y;   float angle = atan2(yv, xv) * (180. / 3.14159);   float diff = fabs(angle - bob.angle);   if (diff > 180)     diff = 360 - diff;   return diff <= degrees; }```

This assumes that bob.angle is measured in the counter-clockwise direction off the positive x axis. Otherwise you may have to flip some coordinates or add something to the angle.

EDIT: oops, I meant counter-clockwise.