Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def loscheck(self, target_pos):
- canSee = True
- for obj in self.world.objs:
- #is the obj.pos + obj.radius in the line between self.pos and target_pos
- #return True
- #find closest point on line (self.pos to target_pos) to obj.pos
- A = self.pos
- B = target_pos
- P = obj.pos
- AB = B - A
- if AB.lengthSq() == 0: #I'm me, ofc I can see myself.
- return False
- AP = P - A
- AB_sq = float(AB.lengthSq())
- AP_dot_AB = float(AP.dot(AB))
- #d = dist from A to closest point to P along line AB
- d = AP_dot_AB / AB_sq
- #D = nearest point on line AB to P
- D = A + AB*d
- DP = P - D
- #is this point inside of the obj radius
- if (DP.length() < obj.radius):
- canSee = False
- return canSee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement