I am back with other newbie question. This time is collision response.
In my game, i control the character (from a top down perspective) with the arrow keys, around a city. The character is always looking to the mouse.
I needed that the character collide with the buldings, so i think using Bounding Boxes.
On the main loop, i keep the position of the character on a variable (lastPosition), then i read the input, so i can move the character accord.
The next thing is check the collision. If the character is in collision, its return to the last position.
The problem is that the character gets stuck in the bulding and can be move only if its is rotated (using the mouse).
obviusly, i am missing something.
This is the code of the coliision:
Code: Select all
bool
Collision::collisionAABB(irr::scene::IAnimatedMeshSceneNode *n1, irr::scene::IMeshSceneNode *n2)
{
core::aabbox3d<f32> box1 = n1->getTransformedBoundingBox();
core::aabbox3d<f32> box2 = n2->getTransformedBoundingBox();
if (box1.intersectsWithBox(box2))
return true;
return false;
}
this is when i check the collision:
Code: Select all
for(unsigned int i =0;i<listProps.size();i++){
scene::IMeshSceneNode* msn = (scene::IMeshSceneNode*)listProps[i];
if(collisionAABB(player->getNode(),msn)){
player->getNode()->setPosition(player->getLastPosition());
}
}
I thought the idea was right, but it still gets stuck in the bulding.
thanks