Example #1
0
    def get_plane_ball_distances(playerHitbox,ballPosition):
        x,y,z = ballPosition
        
        # absolute value everything so that i only need to care about the positive quadrant
        ballPosition = (abs(x),abs(y),abs(z))
        car_eighth = (playerHitbox[0]/2,playerHitbox[1]/2,playerHitbox[2]/2)
        
        # do x
        # front of car. find if ball is within the front area. use the ball value if it is.
        # if ball is not, use the max car value.
        x_to_check = car_eighth[0]
        y_to_check = min(ballPosition[1],car_eighth[1])
        z_to_check = min(ballPosition[2],car_eighth[2])

        point = (x_to_check,y_to_check,z_to_check)
        
        #find distance for plane with x-axis normal
        x_dist = Item.find_distance(point,ballPosition)
        
        
        # do y
        x_to_check = min(ballPosition[0],car_eighth[0])
        y_to_check = car_eighth[1]
        z_to_check = min(ballPosition[2],car_eighth[2])

        point = (x_to_check,y_to_check,z_to_check)
        
        #find distance for plane with x-axis normal
        y_dist = Item.find_distance(point,ballPosition)
            
        
        # do z
        x_to_check = min(ballPosition[0],car_eighth[0])
        y_to_check = min(ballPosition[1],car_eighth[1])
        z_to_check = car_eighth[2]

        point = (x_to_check,y_to_check,z_to_check)
        
        #find distance for plane with x-axis normal
        z_dist = Item.find_distance(point,ballPosition)
        
        return min(x_dist,y_dist,z_dist)
Example #2
0
 def add_all_hits(cls,game):
     hits = []
     frameNo = 1
     buffer = False #if true, allow ball to go beyond mindistance before catching
     lastHitter = None
     hitter = None
     
     # game.ball.distances = []
     
     while frameNo < len(game.ball.positions):
         #get closest distance between ball and player
         ballPosition = game.ball.positions[frameNo]
         minDistance = 2000
         for player in game.players:
             playerPosition = player.positions[frameNo]
             distance = Item.find_distance(playerPosition,ballPosition)
             try:
                 if distance < minDistance:
                     minDistance = distance
                     hitter = player
             except TypeError:
                 pass #distance probably not found, no car
         
         #check if hitter has left buffer distance or someone else has come close to the ball.             
         if minDistance < 350: 
             collideDist = Collision.check_collision(hitter,game.ball,frameNo)
             if collideDist:
                 # print('frame')
                 # print(frameNo)
                 # print(minDistance)
                 # print(collideDist)
                 # print('\n')
                 #find closest approach (look for frame where hit occurs)
                 nextFrameNo = frameNo + 1
                 nextDistance = Collision.check_collision(hitter,game.ball,nextFrameNo)
                 # if distance between ball and car is greater the next frame, hit occurs on this frame.
                 if not nextDistance:
                     nextDistance = 1000
                 
                 # print(nextDistance)
                 # print('\n')
                 if nextDistance >= collideDist:
                     if (hitter==lastHitter) and buffer: pass
                     else:
                         # print('checked distance')
                         try:
                             velocity = game.ball.velocities[frameNo+1]
                         except KeyError:
                             for x in range(1,-2,-1): #check next frame then previous
                                 try:
                                     velocity = game.ball.velocities[frameNo+x]
                                     break
                                 except KeyError: pass
                                 # print(minDistance)
                                 # print('cannot find vel for frame ' + str(frameNo+x))
                             velocity = False
                         if velocity:
                             hit = cls(frameNo,hitter,velocity,game.ball.positions[frameNo],minDistance)
                             # print('found hit,printing frame no and distance')
                             # print(frameNo)
                             # print(minDistance)
                         
                             hits.append(hit)
                             buffer = True
                             lastHitter = hitter
                 else: 
                     # set buffer to false when no collision detected.
                     buffer = False
             
         else: buffer = False
         
         # if minDistance < 300:
             # try:
                 # if collideDist:
                     # game.ball.distances.append(str(collideDist))
                 # else:
                     # game.ball.distances.append('playerdist: ' + str(minDistance))
             # except UnboundLocalError:
                 # game.ball.distances.append('playerdist: ' + str(minDistance))
         # else:
             # game.ball.distances.append('playerdist: ' + str(minDistance))
         frameNo += 1
     return hits
Example #3
0
 def _add_all_hits(cls,game):
     hits = []
     frameNo = 5
     buffer = False #if true, allow ball to go beyond mindistance before catching
     lastHitter = None
     hitter = None
     while frameNo < len(game.ball.positions):
         #get closest distance between ball and player
         ballPosition = game.ball.positions[frameNo]
         minDistance = 500
         for player in game.players:
             playerPosition = player.positions[frameNo]
             distance = Item.find_distance(playerPosition,ballPosition)
             try:
                 if distance < minDistance:
                     minDistance = distance
                     hitter = player
             except TypeError:
                 pass #distance probably not found, no car
         
         #check if hitter has left buffer distance or someone else has come close to the ball.
         bufferDistance = 300
         if (hitter==lastHitter) and buffer:
             if minDistance < bufferDistance:
                 frameNo += 1
                 continue
             elif minDistance > bufferDistance:
                 buffer = False
          
         if minDistance < 250: #will add a hit once past this point
             #find closest approach (look for frame where hit occurs)
             nextDistance = 0
             nextFrameNo = frameNo + 1
                 
             playerNextPosition = hitter.positions[nextFrameNo]
             ballNextPosition = game.ball.positions[nextFrameNo]
             nextDistance = Item.find_distance(playerNextPosition,ballNextPosition)
             #if distance between ball and car is greater the next frame, hit occurs on this frame.
             if nextDistance > minDistance:
                 try:
                     velocity = game.ball.velocities[frameNo+1]
                 except KeyError:
                     for x in range(1,-2,-1): #check next frame then previous
                         try:
                             velocity = game.ball.velocities[frameNo+x]
                             break
                         except KeyError: pass
                         # print(minDistance)
                         # print('cannot find vel for frame ' + str(frameNo+x))
                     velocity = False
                 if velocity:
                     hit = cls(frameNo,hitter,velocity,ballPosition,playerPosition,minDistance)
                 # print('found hit,printing frame no and distance')
                 # print(frameNo)
                 # print(minDistance)
                 
                 hits.append(hit)
                 buffer = True
                 lastHitter = hitter
         frameNo += 1
     return hits