If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
You’ll need to make sure you only attack enemies who are close to you!
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# Pick up the flag.
hero.pickUpFlag(flag)
hero.say("I should pick up the flag.")
elif enemy:
# Only attack if the enemy distance is < 10 meters
if enemy < 10:
hero.attack(enemy)
I’m not sure what I’m doing wrong. Hero won’t attack.
If you’re trying to look for the distance between you and the enemy, you have to put down hero.distanceTo(enemy) in order for the computer to understand the distance between you and the enemy
What is if enemy < 10:? To check a unit’s distance from the hero, you can use a method called hero.distanceTo(unit). In this case, the unit is the enemy.
# If you try to attack a distant enemy, your hero will charge toward it, ignoring all flags.
# You'll need to make sure you only attack enemies who are close to you!
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# Pick up the flag.
hero.pickUpFlag(flag)
hero.say("I should pick up the flag.")
elif enemy:
# Only attack if the enemy distance is < 10 meters
if hero.distanceTo(enemy) < 10:
hero.attack(enemy)
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
Distance = hero.distanceTo(enemy)
if flag:
# Pick up the flag.
hero.pickUpFlag(flag)
elif enemyDistance < 10:
# Only attack if the enemy distance is < 10 meters
hero.attack(enemy)
hero.attack(enemy)
У меня он убил одну сторону врагов а других не видит и они не подходят ,вследовательно герой стоит на месте и ничего ни делает…
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# Возьми флаг.
hero.pickUpFlag(flag)
elif enemy:
# Атакуй врага, если он находится на расстоянии < 10 метров
distance = hero.distanceTo(enemy)
if distance < 10:
hero.attack(enemy)