In my game I have two basic types of objects. Player, and Level.
The player is a single sprite that moves around with
phys->setVelocity(Vect(0, 0));
if(1 == 1) //CHECK THAT SPRING IS NOT CONECTED
{
phys->applyImpulse(Vect(vx, vy));
}
The teeth get their physics bodies like so (eventually this will be a path node)
void genPhysics(bool top, PhysicsInfo* physy)
{
auto size = image->getBoundingBox().size;
auto mat = PhysicsMaterial(1.0, 0.2, 0.2);
auto anchor = image->getAnchorPoint();
PhysicsBody* phys;
if (top)
{
phys = PhysicsBody::createBox(size, mat, Vec2(0, (size.height) * -(anchor.y - 0.5)));//size.height));
}
else
{
phys = PhysicsBody::createBox(size, mat, Vec2(0, (size.height) * -(anchor.y - 0.5) - size.height));
}
phys->setDynamic(false);
phys->setCategoryBitmask(physy->category_tooth);
phys->setCollisionBitmask(physy->contact_tooth);
this->addComponent(phys);
}
And the player gets its physics like so
auto phys = PhysicsBody::createCircle(size.width / 2, playerMat);
phys->setAngularVelocityLimit(0.0);
Charecter->setPhysicsBody(phys);
phys->setCategoryBitmask(physicsi->category_player);
phys->setCollisionBitmask(physicsi->contact_player);
Here is the PhysicsInfo class it keeps referencing
class PhysicsInfo
{
public:
int category_player = (0x1 << 2);
int category_tooth = (0x1 << 3);
int category_wall = (0x1 << 4);
int category_sensor = (0x1 << 5);
int contact_player = (0x1 << 2) | (0x1 << 3) | (0x1 << 4);
int contact_tooth = (0x1 << 2);
int contact_wall = (0x1 << 2);
int contact_sensor = 0x0;
};
Some things to note:
- Any collision with level geometry causes sprite to go in, and gradually be pushed out.
- Debug drawing does show a collision
- Although rotation is locked the sprite does somehow find a way to rotate
- The level edges physics bodies do not behave like this, they are 4 boxes that extend from the edge, then out abit.
- The level geometry is constantly intersecting.