The ball keeps on hitting the red skeletons instead of the blue ones, please help me.
My code:
# Push the ball to knock over all the blue skeletons without hitting any red ones.
# The blue skeletons can be found as enemies.
while True:
ball = hero.findNearest(hero.findByType("ball"))
ballPos = ball.pos
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
friend = hero.findNearest(friends)
Vector = enemy.pos
distance = Vector.subtract(Vector, ballPos)
pos = Vector.add(distance, 5)
hero.command(friend, "move", pos)
hero.command(friend, "move", ballPos)
You should first command pez move to vector, then to the center, then to the vector
hero.command(friend, 'move', vector)
hero.wait(1)
hero.command(friend, 'move', center)
hero.wait(1)
hero.command(friend, 'move', vector)
Like this?
# Push the ball to knock over all the blue skeletons without hitting any red ones.
# The blue skeletons can be found as enemies.
# The blue skeletons can be found as enemies.
while True:
ball = hero.findNearest(hero.findByType("ball"))
center = ball.pos
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
friend = hero.findNearest(friends)
vector = enemy.pos
distance = Vector.subtract(vector, center)
pos = Vector.add(distance, 5)
hero.command(friend, 'move', vector)
hero.wait(1)
hero.command(friend, 'move', center)
hero.wait(1)
hero.command(friend, 'move', vector)
Thanks for the help! I eventually found out what I did wrong.
So, did it help you?
(Also mark the solution if you’re finished)