Hi folks,
I'm going to do my best to explain this...
Part of the app (game) I am developing uses a fairly traditional "platform" system, and thanks to the new Kinematic bodies in 2.1 this has become a whole lot easier.
I'm trying to create a "one sided" platform (as suggested in the doco "Pre-Solve Event" section). Essentially I am checking the normal vector of the contact and disabling the contact if it's not "0,1".
I have a rectangular platform and the contact disabling works as expected (ie if I "hit" the platform with a body from underneath it passes through), however I've hit a really weird problem:
My "player" character is currently represented by a simple circle shape. As this shape approaches the edge of the platform it reaches a point (somewhere on the corner) where my contact normal vector is not within the accepted range and the contact is disabled. At this point, the circle shape gets "stuck". That is, I can't move it in any direction.
I have discovered that the reason I can't move "upwards" is that box2d is continually increasing the velocity of the body downwards (to infinity as far as I can tell). So every step of the world increases the downward velocity of the body, hence I can't move up. But I can't move left or right either. (btw, I am manually setting linear velocity to move).
This only seems to happen on the corner of the platform. I have verified that the contact is being disabled each step when on this point.
It seems somehow that the circle shape is "supposed" to be falling, but is still colliding with the platform.. however because I have disabled the contact I'm guessing that box2d is thinking it's falling so increasing its "fall rate" but also preventing the shape from moving due to a collision with the corner of the platform. Complete guesswork here.
Is there any condition in which the cancellation of a contact would NOT prevent a collision? As I mentioned, box2d is correctly identifying that there IS a contact (every step) and PreSolve is being called (every step) and I am disabling the contact.
Curiously, I see the PreSolve being called, but do not see BeginContact or EndContact.. which would be expected given I have disabled the contact. So it seems the contact disabling is being registered, but somehow my shape is still colliding.
Maybe it has something to do with using a circle shape?
Anyone got any ideas?
Cheers,
Jason.
P.S.
Some further info:
This "stickyness" does not manifest if I remove the contact disabling.
The circle only gets stuck if it "creeps" to the edge. If I move at full speed it flies of the platform as expected.
I WAS experimenting with fixed rotation on the circle, and thought this may be related but that same thing happens in either case.
While the contact is "valid" I am adjusting the circle's velocity to match the platforms (so the "player" stays on the platform), but I have also disabled this and same problem exists.
================
UPDATE
================
So after some experimentation, things have gotten VERY strange. I changed my player body to be a box shape (polygon, setasbox) to see if it was maybe an issue with circles. When I touched the platform on the "solid" side, the same problem occurred. That is, the player box got completely stuck, and the linear velocity just started climbing. The strange thing was that I have other "platforms" in the scene, and none of these other ones exhibited the same problem. The ONLY difference between the problematic platform and the others was the order of creation.
It seems if I create my "player" body BEFORE I create any platforms, those platforms exhibit the same problem. It was just coincidence that the problematic platform was created AFTER the player body.
I fear this is getting more and more complicated, and difficult to reproduce without a test case. I don't have the test bed operational (I am compiling/running in Android) so I'm not sure I can create a test case. Just hoping someone has an insight here...?
I'm going to do my best to explain this...
Part of the app (game) I am developing uses a fairly traditional "platform" system, and thanks to the new Kinematic bodies in 2.1 this has become a whole lot easier.
I'm trying to create a "one sided" platform (as suggested in the doco "Pre-Solve Event" section). Essentially I am checking the normal vector of the contact and disabling the contact if it's not "0,1".
I have a rectangular platform and the contact disabling works as expected (ie if I "hit" the platform with a body from underneath it passes through), however I've hit a really weird problem:
My "player" character is currently represented by a simple circle shape. As this shape approaches the edge of the platform it reaches a point (somewhere on the corner) where my contact normal vector is not within the accepted range and the contact is disabled. At this point, the circle shape gets "stuck". That is, I can't move it in any direction.
I have discovered that the reason I can't move "upwards" is that box2d is continually increasing the velocity of the body downwards (to infinity as far as I can tell). So every step of the world increases the downward velocity of the body, hence I can't move up. But I can't move left or right either. (btw, I am manually setting linear velocity to move).
This only seems to happen on the corner of the platform. I have verified that the contact is being disabled each step when on this point.
It seems somehow that the circle shape is "supposed" to be falling, but is still colliding with the platform.. however because I have disabled the contact I'm guessing that box2d is thinking it's falling so increasing its "fall rate" but also preventing the shape from moving due to a collision with the corner of the platform. Complete guesswork here.
Is there any condition in which the cancellation of a contact would NOT prevent a collision? As I mentioned, box2d is correctly identifying that there IS a contact (every step) and PreSolve is being called (every step) and I am disabling the contact.
Curiously, I see the PreSolve being called, but do not see BeginContact or EndContact.. which would be expected given I have disabled the contact. So it seems the contact disabling is being registered, but somehow my shape is still colliding.
Maybe it has something to do with using a circle shape?
Anyone got any ideas?
Cheers,
Jason.
P.S.
Some further info:
This "stickyness" does not manifest if I remove the contact disabling.
The circle only gets stuck if it "creeps" to the edge. If I move at full speed it flies of the platform as expected.
I WAS experimenting with fixed rotation on the circle, and thought this may be related but that same thing happens in either case.
While the contact is "valid" I am adjusting the circle's velocity to match the platforms (so the "player" stays on the platform), but I have also disabled this and same problem exists.
================
UPDATE
================
So after some experimentation, things have gotten VERY strange. I changed my player body to be a box shape (polygon, setasbox) to see if it was maybe an issue with circles. When I touched the platform on the "solid" side, the same problem occurred. That is, the player box got completely stuck, and the linear velocity just started climbing. The strange thing was that I have other "platforms" in the scene, and none of these other ones exhibited the same problem. The ONLY difference between the problematic platform and the others was the order of creation.
It seems if I create my "player" body BEFORE I create any platforms, those platforms exhibit the same problem. It was just coincidence that the problematic platform was created AFTER the player body.
I fear this is getting more and more complicated, and difficult to reproduce without a test case. I don't have the test bed operational (I am compiling/running in Android) so I'm not sure I can create a test case. Just hoping someone has an insight here...?