ivansafrin/Polycode — Issue #57: SetTransform() after a collision results in mystery warping?!
Author: mcclure
Created: 2011-11-24 21:19:41+00:00
State: open

I got a VERY strange behavior in this particular revision of my LUA polycode project: https://bitbucket.org/runhello/luatest/changeset/8a5544f67203
where after calling SetTransform(), the object thus transformed would "snap back" to a particular position on the very next frame.

This came up because of issue #29 above where removing objects from a physics space causes a crash; I had to do *something* with the bullets in my game after they were "destroyed", so I handled this by setTransforming() them to be at a random coordinate in the vicinity of 10000,10000, far outside of the window. If I did this naively, here is what I would see:

The bullet collides with an asteroid. Because I think (?? may file an issue about this later) bad things happen if you setTransform during a collision handler, I put the collision-detected bullet into a "dying bullets" list. On the next update loop, I setTransform() all the "dying bullets" to 10000,10000 plus a random offset, and set their velocities to zero.

When I do this, the bullet will disappear for one frame, then suddenly on the very next frame snap back to *ALWAYS THE SAME POSITION*-- it would materialize somewhere around (300,100), every single time this happened the bullet would appear in the same place-- with about the same velocity it had before the collision it had but a seemingly random trajectory. If the same bullet then hit another asteroid and went through the banishment procedure again, the second time it would take and would NOT return to the mysterious (300,100) position.

The way I eventually got around this was that the "dead bullets", the ones which have collided with an asteroid, go into a "dead bullet" array, stay there forever, and get re-SetTransformed outside of the visible space on every single frame. However it is not reasonable to have to take this workaround. I don't even know what's happening here but it looks like a bug at polycode's end.