Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
How to determine if an object is facing another object?
I am writing a basic space ship simulation and I need to tell if one object is facing another object. So the ship can determine if it should fire. (I use an objects x axis directional vector as the direction the object is facing)
At the moment I determine the xy plane of object A and see how far away object B is from this plane. Then I determine the zx plane of object A and see how far away object B is from this plane. Then I use Pythagorus to determine how far away object B is from the line formed by object A's x axis directional vector.
This is very computationaly expansive. Is there a better simpler way to tell if an object is in line with another (ie Object A has object be in it's sights)