Help with missile dodging please

Hi guys, can you help me with missile dodging please?
My shamans arent dodging the enemy shots.
Here is my code.

summonTypes = ['fire-shaman', 'lightning-shaman', 'water-shaman', 'earth-shaman']

def commandLS():
    wizards = hero.findFriends()
    for wizard in wizards:
        if wizard.type == 'lightning-shaman':
            dodgeMissiles(wizard)
            enemies = hero.findEnemies()
            enemy = wizard.findNearest(enemies)
            shot = wizard.findNearest(hero.findEnemyMissiles())            
            if shot:
                if wizard.distanceTo(shot) < 8:
                    dodgeMissiles(wizard)
            
            if enemy and wizard.canCast("chain-lightning"):
                if shot:
                    if wizard.canCast("chain-lightning"):
                        hero.command(wizard, "cast", 'chain-lightning', enemy)
            elif enemy:
                hero.command(wizard, "attack", enemy)
def commandES():
    wizards = hero.findFriends()
    for wizard in wizards:
        if wizard.type == 'earth-shaman':
            shot = wizard.findNearest(hero.findEnemyMissiles())
            if shot:
                if wizard.distanceTo(shot) < 8:
                    dodgeMissiles(wizard)
            friends = wizard.findFriends()
            friend = wizard.findNearest(friends)
            enemies = hero.findEnemies()
            enemy = friend.findNearest(enemies)
            for friend in friends:
                goods = []
                if friend.type <> 'flame-tower' and friend.type <> 'earth-tower' and friend.type <> 'water-tower' and friend.type <> 'soldier' and friend.type <> 'archer':
                    goods.append(friend)        
            target = wizard.findNearest(goods)
            if target and wizard.canCast("earthskin"):
                if shot:
                    if wizard.canCast("earthskin"):
                        hero.command(wizard, "cast", 'earthskin', target)
            elif enemy:
                hero.command(wizard, "attack", enemy)                
    
def commandWS():
    wizards = hero.findFriends()
    for wizard in wizards:
        if wizard.type == 'water-shaman':
            shot = wizard.findNearest(hero.findEnemyMissiles()) 
            if shot:
                if wizard.distanceTo(shot) < 8:
                    dodgeMissiles(wizard)
            friends = wizard.findFriends()
            friend = wizard.findNearest(friends)
            for friend in friends:
                goods = []
                if friend.type <> 'flame-tower' and friend.type <> 'earth-tower' and friend.type <> 'water-tower' and friend.type <> 'soldier' and friend.type <> 'archer':
                    goods.append(friend)
            enemies = hero.findEnemies()
            target = friend.findNearest(goods)
            enemy = wizard.findNearest(enemies)
            if target and wizard.canCast("haste"):
                hero.command(wizard, "cast", 'haste', target)      
                
            elif enemy:
                hero.command(wizard, "attack", enemy)
def commandFS():
    wizards = hero.findFriends()
    for wizard in wizards:
        if wizard.type == 'fire-shaman':
            
            dodgeMissiles(wizard)
            friends = wizard.findFriends()
            friend = wizard.findNearest(friends)
            for friend in friends:
                goods = []
                if friend.type <> 'flame-tower' and friend.type <> 'earth-tower' and friend.type <> 'water-tower' and friend.type <> 'soldier' and friend.type <> 'archer':
                    goods.append(friend)
            enemies = hero.findEnemies()
            enemy = wizard.findNearest(enemies)
            shot = wizard.findNearest(hero.findEnemyMissiles())            
            if shot:
                if wizard.distanceTo(shot) < 8:
                    dodgeMissiles(wizard)
            target = wizard.findNearest(goods)           
            target = wizard.findNearest(goods)
            if target and wizard.canCast("flame-armor"):
                if shot:
                    if wizard.canCast("flame-armor"):
                        hero.command(wizard, "cast", 'flame-armor', target)                
            elif enemy:
                hero.command(wizard, "attack", enemy)
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)
def commandShaman():
    commandFS()
    commandWS()
    commandES()
    commandLS()
def dodgeMissiles(wizard):
    shot = wizard.findNearest(hero.findEnemyMissiles())
    if shot:
        d = Vector.subtract(shot.pos, wizard.pos)
        d = Vector.normalize(d)
        d = Vector.multiply(d, 8)
        moveToPos = Vector.add(wizard.pos, d)
        hero.command(wizard, "move", moveToPos) 
def steal():
    if hero.team == 'humans':
        commandShaman()
        hero.moveXY(89, 72)
        commandShaman()
        hero.moveXY(132, 72)
        commandShaman()
        hero.moveXY(130, 115)
        commandShaman()
        hero.moveXY(131, 26)
        commandShaman()
        hero.moveXY(131, 72)
        commandShaman()
        hero.moveXY(88, 65)
        commandShaman()
    elif hero.team == 'ogres':
        commandShaman()
        hero.moveXY(76, 72)
        commandShaman()
        hero.moveXY(34, 71)
        commandShaman()
        hero.moveXY(32, 27)
        commandShaman()
        hero.moveXY(32, 113)
        commandShaman()
        hero.moveXY(41, 76)
        commandShaman()
        hero.moveXY(83, 73)
        commandShaman()
def getGold():
    if hero.canCast("haste"):
        hero.cast("haste", self)
    item = hero.findNearestItem()
    if item and hero.time < 20:
        hero.move(item.pos)
    if hero.time >= 25:
        steal()
while True:
    commandShaman()
    summonTroops()
    getGold()

Your code looks like you’re asking your units to move towards the enemy projectiles rather than away, is that what happens? Read Vector.subtract(shot.pos, wizard.pos) as “get the vector pointing from wizard.pos to shot.pos.”

I’m going to request that you refrain from pinging or messaging me directly when 1. you haven’t given the problem that much thought and 2. you’re not going to spend the effort to describe the problem or provide a MVE.

1 Like

Before you start with commanding shamans to dodge missiles, make a sandbox level where you have to maneuver your own hero to dodge missiles. You should review the Glacier levels once more(Look especially to Skating Away, Circle Walking, and Bombing Run) before you start.

1 Like

Please keep these threads public and not in PM’s.