I tried to implement from this site linear-algebra on how do I check the field of view using dot product. But when I check the angle to the given fov angle, I am not getting the desired result. Instead of getting the field of view of 45 degree, I am getting 90 degree. What am I doing wrong?
Vector2 start = Mapper.transform.get(owner).position;
Vector2 end = Mapper.transform.get(target).position;
float facingAngleRad = 0;
Vector2 ownerOrientation =
new Vector2((float)Math.cos(facingAngleRad), (float) Math.sin(ficingAngleRad));
Vector2 targetOffset = tmp1.set(end).sub(start);
float product = ownerOrientation.nor().dot(targetOffset.nor());
float checkAngle = (float) Math.acos(product);
float FIELD_OF_VIEW_ANGLE = 45 * MathUtils.degeeToRadians;
if(checkAngle < FIELD_OF_VIEW_ANGLE) {
// in the field of view
}
In the below image, green is the desired field of view (45 degree), but I'm getting 90 degree (red)