Precision kicking help!

hmm, I think I get what you are trying to do, but the peasant still might bump the ball on accident when she moves to point1.

Also, she doesn’t have enough time to get to point1 before she gets commanded to move to point2. Since move doesn’t wok like moveXY she will never get to point1

Have you done the level Broken Circles? I used the idea from that level to move around the ball in a circle and decide when to move towards the center.

3 Likes

She only goes to point1 then stops. Why is this happening?

1 Like

I am confused. The peasant still only moves to point1 and stops. Some help please?

Here is my code:

Thanks!
(Click on image to magnify)

@Mr-Borges please respond

Try putting the vector stuff and ball info inside the loop.

Does it work? @kaiduck

1 Like

Every single thing is already inside the loop. Seriously, can I have some real help like @Mr-Borges gave to me?

Sorry I haven’t been on in a long time. I’m a school teacher and I was on summer vacation :slight_smile:

Now I’m back at school and my students are all doing code combat. :slight_smile:

@Neel_Sharma can you please cut and paste your code and format it with the three tick marks?

I’ll actually run your code and see what it is doing.

2 Likes

He means format your code according to the FAQ. Also you need to give more information about what is happening, if there are any error messages etc.

Yes @Luke10 thank you.

1 Like

I already know how to format, thank you.
Here is my code (In the post that I made above there is the same code, and it shows the error too.):

loop:
    ball = hero.findNearest(hero.findByType("ball"))
    ballPos = ball.pos
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    heroPos = hero.pos
    nubPos = enemy.pos
    newVector = Vector.subtract(nubPos, ballPos)
    direction = Vector.normalize(newVector)
    dm = Vector.multiply(direction, -3)
    finalVector = Vector.add(ballPos, dm)
    flag = hero.findFlag("black")
    if flag:
        point1 = {"x": 40, "y": 25}
        hero.command(friend, "move", point1)
        if friend.distanceTo(finalVector) < 2:
            hero.command(friend, "move", finalVector)
        else:
            point2 = {"x": 34, "y": 35}
            hero.command(friend, "move", point2)
            if friend.distanceTo(finalVector) < 2:
                hero.command(friend, "move", finalVector)
            else:
                point3 = {"x": 40, "y": 45}
                hero.command(friend, "move", point3)
                if friend.distanceTo(finalVector) < 2:
                    hero.command(friend, "move", finalVector)
                else:
                    point4 = {"x": 48, "y": 37}
                    hero.command(friend, "move", point4)
                    if friend.distanceTo(finalVector) < 2:
                        hero.command(friend, "move", finalVector)
                        hero.command(friend, "move", ballPos)

Thanks

It is a little hard for me to figure out what you are trying to do. I think you are wanting to time your peasant movement with a black flag. Have her move in a diamond shape around the ball and then move into kicking position when she gets close.

hero.command(friend, "move", point1)

This command does not change the peasant’s pos to be point1, it only makes them take one step towards point1.

What I mean is, you need to be able to just get your peasant to move around the ball at all before you’ll be able to kick in the right direction. Maybe just work on that one piece first.

if friend.distanceTo(finalVector) < 2:
    hero.command(friend, "move", finalVector)

2 is a very small distance, the 4 points you are using are much more than 2 units apart

hero.command(friend, "move", finalVector)
hero.command(friend, "move", ballPos)

I think these two should always go together. Once she is at finalVector she should always do a kick by moving to ballPos. Problem is again, these two commands will not make the peasant be positioned at finalVector and then be positioned at ballPos. These commands will only make her move one time towards those positions.

Finished level thanks!

1 Like

So do you have nalfar yet

We can buy Nalfar without completing the levels.

1 Like

so do you have nalfar?

Of course! I had him before finishing this lvl.

1 Like

me too. (20 characters)

Nice! :wink: (20 characters)

1 Like

yay my bad forgot you can just buy it

I can’t command my soldiers to move they hate me!