so i am making a tower defense game and need to find a way to make the towers shoot at enemy’s if they are in so many blender units of the tower.
i found that you cant change witch enemy you are shooting at with only logic bricks.
i am rather inexperienced in blender python this is my first script that is more than showmouse.
so i have my robots attaching your base and you can place towers.
on my tower i have a set up like this.
near sensor => python controller => track to actuator
radar sensor => and controller => add object actuator (shoot)
my shooting system works great if there is a robot in front of them they will shoot.
my aiming system works as long as i only have onerobot with the same name every time.
then i can just put in the robots name in track to and replace my python controller with a and controller.
this is the script that i have so far.
import GameLogic
def main():
cont = GameLogic.getCurrentController()
own = cont.owner
near = cont.sensors['near']
track = cont.actuators['track']
if near.positive:
track.setObject('OBrobot')
cont.activate(track)
else:
cont.deactivate(track)
main()
this is the script i am trying to make
if near is true
get name of near’s hit object
set track to track near’s hit object
keep tracking that object until object is not in near’s range or has died
when that happens find a new target
my current problem is that i cant figure out how to change tracks target object.
i will also need to get near’s hit object and figure out if it is still in range even when there are multiple objects in range
this may be a easy to you but please help
I’m trying to get something similar to this to work, but can’t. I see your code, and I am doing the same. I am trying to check a property on my enemy to see what node it is supposed to be going after (Node.001, Node.002, etc.), then set the trackTo actuator to track to that node. Here is what I have:
Now there are two problems that I know of. First, I am not able to set the node property integer in the way I am trying, which I know works for strings using .Text. But I can’t figure out how to do it like this. Also, even if I put “target = ‘Node.001’”, the enemy still does not track that node. So it’s not setting the object either. And I’ve also tried “trackTo.object = target” which did not work either. Any help would be appreciated.