Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision function problem
#1
I am writing python code inside Turtle import. I am making a program where one turtle chases another turtle. I want my Turtle player to change colors if the other turtle catches up to him. Right now I have created a function:
def collision_decision():
    if chaser.pos() = player.pos():
        player.color("orange","green")
    else:
I am trying to set it so that when both turtles have the same position (when the chaser turtle has caught up with the player) that my player turtle changes colors. However, now my code won't run and it says it doesn't recognize the line "if chaser.pos() = player.pos():"

Any advice you could give would be appreciated. If you would like the whole code I can give it. Just let me know.
Reply
#2
There is a difference between "=" and "==" Note also that the x coordinates of whatever figure you are using, can catch the other figure while the y coordinates are different, higher or lower, and vice versa.
Reply
#3
I don't know if this will help you, but you need to change = to ==. = is an assignment operation in Python.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star I was making code for collision for my character izmamonke 2 2,095 Aug-06-2021, 04:30 PM
Last Post: izmamonke
  SOLVED - Collision detection - TURTLE OuateDePhoque 9 11,401 Nov-18-2020, 06:29 PM
Last Post: OuateDePhoque
  bouncing ball with variable collision points (in time) Zhaleh 1 2,385 Jul-24-2020, 02:54 PM
Last Post: Marbelous
  Player object wont recognize collision with other objects. Jan_97 3 2,725 Dec-22-2019, 04:08 PM
Last Post: joe_momma
  Union of dictionaries (taking max value on collision) meee 5 3,773 Jan-17-2018, 09:14 PM
Last Post: Mekire
  Need help figuring out Sprite.Group Collision code PySam 3 3,382 Sep-15-2017, 03:00 AM
Last Post: PySam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020