I want to wright a script to output the closest object with a spicific game property say “bad guy” So i can edit an aiming script to select the closest enemy in my game ensted of having to put the name of the enemy in my script. Here is my aim script.
pi = 3.141592653589793238462
controller = GameLogic.getCurrentController()
p2 = controller.getOwner()
p1 = GameLogic.getCurrentScene().getObjectList()[“OBp1”]
p1x = p1.getPosition()
p1y = p1.getPosition()
p1z = p1.getPosition()
pex = p2.getPosition()
pey = p2.getPosition()
pez = p2.getPosition()
xdist = (p1x - pex)
ydist = (p1y - pey)
p1ang = [0.0, 0.0, (((math.atan((ydist/xdist)))))]
p1rot= [0.0, 0.0, (pi+((math.atan((ydist/xdist)))))]
if xdist > 0:
if xdist < 0:
basicly it uses trigenomatry to find the angle between the script object and the object p1 and sets its angle to that. Is it possable to use the distance formula to select the closest “bad guy” for aiming at.
this script was for an enemy to aim at the player aka p1 short for “Player 1” which works great because there is only one player in the game. but i want an auto aim feture in my game and it would be nice if it would aim at the closest enemy and not just the predefined one.
Please Help and if i confused you tell me. yes i know i can’t spell.