3

This is the code. I don't know why but the goal does not move when I run the code. I am really new to coding so excuse me if it is something silly. Thank you so much for all your help.

    if isCollision(player, goal):
        goal.setposition(random.randint(-300, 300), random.randint(-300, 300))
        goal.right(random.randint(0,360))
        goal.forward(1)
        

Should not this make the goal move? No errors were detected in the code. This is a link to the code: https://pastebin.com/mczU1xpu

  • 1
    I tried your code, it works fine, goal moves to random position on collision. did you try debugging inside the if statement? – Mutaz-MSFT Jul 25 '21 at 02:57
  • 1
    first you could use `print()` to see what you have in variables and which part of code is executed. Maybe you have wrong values in variables or `isCollision` gives `False` and this code is never executed. Did you run code in console/terminal to see error messages? – furas Jul 25 '21 at 04:13
  • 1
    code works for me. Do you runs in some IDE? Maybe problem is IDE. Did you try to run it directly `python script.py`? – furas Jul 25 '21 at 04:17
  • Hey, thank you for your help. I think I wasn’t clear enough. The goal moves for me, but it disappears and appears somewhere else. I want it to move around so the turtle chases it if that makes any sense. – Abdulrahman Jul 25 '21 at 06:07
  • As in, I want the goal to be moving around the same way the turtle or player moves around – Abdulrahman Jul 25 '21 at 06:28

1 Answers1

1

Try moving it with

setx()
sety()

With "sety()" you can control the y-axis and "setx()" you control the x-axis

And instead of using goal.setposition(random.randint(-300, 300), random.randint(-300, 300)) use goal.goto(random.randint(-300, 300), random.randint(-300, 300))

AABULUT
  • 50
  • 4