Consider the following code
Now reading the documentation would lead me to believe that calling SetTransform would lock it in place with the Actor invoking the Move function. As a result, If i were to call Move(400,300); every time the game steps, It can be assumed that the body will stay at the scaled location of 0.4 and 0.3
However, my console output shows me results to the contrary. It shows the body moving according to the physics simulation while the graphic the actor displays stays in place, where the code that moves the graphic is as follows
Very very puzzling... anyone care to shed some light on this anomoly? My goal is to be able to move actors around and still be able to generate collisions with all types of objects since kinematic bodies wont interact with other kinematic bodies. Setting the body to kinematic on it's movement will keep the body in place.
EDIT: I've managed to make a work-around for the time being. What I am doing is calling world->Step() only after all the game's entities have stepped and it seems to work all the same. That way, i can call Move (which sets the body's type to kinematic and sets its transform) and then the derived entity must call SetPhysical, which sets its type to dynamic. Then when the world is updated, collision events are generated. At that point, the entities will be physical and collision events will be generated even if the entity called Move or Rotate.
Erin, this is only a suggestion, but if there was a way to set the location and orientation of a dynamic body, then that would be of great to help to people who are wraping Box2D. Either that, or since kinematic bodies can also move, having them generate collision events between each other would be even better. Im going to keep tinkering and see if I can come up with a better solution.
Code:
void Actor::Move(float x, float y)
{
base_body->SetType(b2_dynamicBody);
this->x = x; this->y = y;
base_body->SetTransform(b2Vec2(x*PHYS_SCALE,y*PHYS_SCALE), DEG2RAD(angle));
}
{
base_body->SetType(b2_dynamicBody);
this->x = x; this->y = y;
base_body->SetTransform(b2Vec2(x*PHYS_SCALE,y*PHYS_SCALE), DEG2RAD(angle));
}
Now reading the documentation would lead me to believe that calling SetTransform would lock it in place with the Actor invoking the Move function. As a result, If i were to call Move(400,300); every time the game steps, It can be assumed that the body will stay at the scaled location of 0.4 and 0.3
However, my console output shows me results to the contrary. It shows the body moving according to the physics simulation while the graphic the actor displays stays in place, where the code that moves the graphic is as follows
Code:
void Actor::PostStep()
{
b2Vec2 pos = base_body->GetPosition();
// m2dtransform moves a node in the graphics engine to the specified position in the OGL viewport
m2dTransform(graphic->GetNodeHandle(), pos.x*PHYS_UNSCALE, pos.y*PHYS_UNSCALE, angle);
}
{
b2Vec2 pos = base_body->GetPosition();
// m2dtransform moves a node in the graphics engine to the specified position in the OGL viewport
m2dTransform(graphic->GetNodeHandle(), pos.x*PHYS_UNSCALE, pos.y*PHYS_UNSCALE, angle);
}
Very very puzzling... anyone care to shed some light on this anomoly? My goal is to be able to move actors around and still be able to generate collisions with all types of objects since kinematic bodies wont interact with other kinematic bodies. Setting the body to kinematic on it's movement will keep the body in place.
EDIT: I've managed to make a work-around for the time being. What I am doing is calling world->Step() only after all the game's entities have stepped and it seems to work all the same. That way, i can call Move (which sets the body's type to kinematic and sets its transform) and then the derived entity must call SetPhysical, which sets its type to dynamic. Then when the world is updated, collision events are generated. At that point, the entities will be physical and collision events will be generated even if the entity called Move or Rotate.
Erin, this is only a suggestion, but if there was a way to set the location and orientation of a dynamic body, then that would be of great to help to people who are wraping Box2D. Either that, or since kinematic bodies can also move, having them generate collision events between each other would be even better. Im going to keep tinkering and see if I can come up with a better solution.