You should have a record of all your bats, using a type will do:
(untested! :P)
Then you'd create your bat & balls:
Now just call the function in your game, passing it the 'bat' entity
(untested! :P)
Type tBall Field entity End Type
Then you'd create your bat & balls:
bat = LoadMesh("myBat.x") Local ball.tBall For i = 1 to 3 ball = New tBall ball\entity = CreateShpere() Next
Now just call the function in your game, passing it the 'bat' entity
Function NearestBall(bat) Local ball.tBall Local nearestBall.tBall Local nearestDist# ;Assume first tBall instance is the nearest nearestBall = First tBall nearestDistance = EntityDistance(bat,nearestBall\entity) For ball = Each tBall If ball <> nearestBall dist = EntityDistance(bat,ball\entity) If dist < nearestDist nearestBall = ball nearestDist = dist End If End If Next Return nearestBall\entity End Function