I am converting my Logic Bricks all to python components.
Now I’m trying to convert a collision sensor.
All the components work just as well as the logic bricks in regards to performance and the logic is around 28-30 %.
But now I wrote the following method to replace a collision sensor and the game starts lagging like crazy… the logic starts around that value but shortly after starts to increase more and more. At the end it’s around 70 % (it would probably go even further)
Anyways… this is the code im using to replace the collision sensor:
if object != self.twintip: <----self.twintip = self.object
if "rail" in object:
self.grinding = True
self.twintip["grinding"] = True
self.grinding = False
self.twintip["grinding"] = False
Any idea what is causing that overhead?
Thanks a lot in advance!!!
Is that script running more than once? I could imagine it lagging if you have heaps of callbacks on the same object. The way you describe it getting worse as the similation runs longer makes me think of that possibility.
You can find out by putting a print statement after:
Yeah, it is indeed a function in a function that is called every frame…
But how else could I detect a collision then? It must be checking all the time if that collision will happen or not, or am I understanding that collisionCallback function wrong?
You only need to add the callback once. Once it’s there, it’ll call the function you’ve provided every time a collision happens.
In a real world situation, you might say to someone “call me when you want to go out to dinner”. You only needed to say that once, but you will get a call every time the criteria is met.
Hell yeeahaa, thank you so much, I got it to work
I’m so stoked!