Python Collision Callback not working properly?

Can someone help me figuring out why the output of this code sometimes keeps True although no more collision with the property “water” is happening?

in the start method:


    def on_water_collision(self, object):  # checking if contact with water
        if "water" in object:
            self.kiteCrash = True
            self.kiteCrash = False

TBH, for this use case, the sensor would be more appropriate.

The callback occurs when the collision starts, so that’s why it sets the variable to true when you initially collide with water. There are two problems with your code:

  1. If your kite collides with something other than the water, while still colliding with the water, then the variable will be set to false.
  2. You have no way of knowing when you stop colliding with the water.

What you actually want to do is find out when the collision with the water ends.
Maybe there is a callback for the end of collision? Or, can you loop through all objects that your kite is colliding with and check if one of them is the water?

1 Like

Ok, I think I will do it with the sensor then… That will save me all that collision callback headache :smiley:
And just call the property from within the code