Why do collisions behave differently in Android than in iOS?

I am using Box2D to simulate the physics world independently of my sprites, and I update the position of my sprites based on the position of b2body.

I have a player that consists of two fixtures. One fixture is not a sensor and can make contact with the ground. The other fixture is a sensor and is used to check for contacts with things like powerups eatables etc.

. I have some bodies (eatables, powers) in which the fixture consists of a single sensor that can make contact with the player sensor.

In iOS everything works fine - when the player collides with the powerup / eatable, he continues running as if nothing is wrong. But in Android he bounces off the powerup.

What could be the problem ? The plist file generated by physics editor is the same for both. Why should the simulation be different ? Box2d is part of cocos2d, so the library is the same and should be the same for both.

I am using cocos2d-x 3.7

This is due to a bug in the GB2ShapeCache.cpp file provided on the Physicseditor site. While it works fine for iOS, it screws up the boolean conversion of isSensor on android, which is why sensors don’t behave like sensors.

A simple fix is to just read the string yourself and check if it is true / false and set basicData.isSensor = true yourself.

1 Like

I also had this problem with cocos 3.14 in ios simulator (not only android)
I solved this issue modifying GB2ShapeCache-x.cpp

// Former Line
// basicData.isSensor = (bool)static_cast<String *>(fixtureData->objectForKey(“isSensor”))->intValue();

// New lines
std::string isSensorStr = static_cast<String *>(fixtureData->objectForKey(“isSensor”))->getCString();
basicData.isSensor = ( isSensorStr.compare(“true”) == 0) ? true : false;