How to tell if one actor is "facing" another actor?
![maxerov](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
I'm making a game where Actor 1 moves and turns randomly and when it faces Actor 2 an event is triggered. I have made a rudimentary system with complicated math but it has a lot of bugs and doesn't really work. Does anyone have any ideas as to how to do this?
Comments
For instance, if actor A's VecterToAngle to actor B (you'll need to constrain B's x and y as global attributes) is less than 180 and more than 0, then it's "facing" actor B.
heroX
heroY
Rotation
Use COS/SIN to make that actor move in a circle.
If the other actors overlap with that actor, it's in the hero's line-of-sight.
If COS/SIN is scary to you, The Unofficial GameSalad Textbook has a great math chapter.
I was actually going to have it the other way around so that multiple instances of the Actor 2 would be looking for the Actor 1 (or hero actor). Would your system still work for that?
http://gamesalad.com/forums/topic.php?id=22982
I added line of sight to BOT. It works great. There's an invisible actor that does much of the work. It's position/rotation is constrained to TANK's X,Y and rotation data. The rest is just using rules to detect for overlaps.
That's tricky.
If self.rotation = vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y)
Then change self.aggressive to True
You could add a little bit of a variance too with two rules...
If self.rotation < vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) +10
If self.rotation > vectorToAngle(TANK.X - Self.position.X , TANK.Y - Self.position.Y) -10
I'm not sure if this works, but it might be something to try.