I am trying to get a fireball to change direction when it collides with anything. I was hoping Irrlicht had a onCollision() call but no dice. I already have generic collision detection working (aka ball hits wall and stops).
What I decided to do was to get the position of where my fireball should be (currentPosition+direction) and then update the position of the fireball with this new position. Then check the position after it has been updated and if this position is not the same as (position+direction) then collision has occured.
This did not work and I have tried several different ways of doing the above and I get the same result, (the fireball just goes back and forth in a small space in midair). It seems that when I change the direction it just changes right back. Here is my code:
*NOTE: ps4 is my fireball
Code: Select all
while(irrDevice->run()) {
//save position where ball should be
newLocation = newLocation = ps4->getPosition()+direction;
// move fireball
ps4->setPosition(newLocation);
//Do scenecrap
irrDriver->beginScene(true,true,0);
irrSceneMgr->drawAll();
irrDriver->endScene();
//Check for collision
if(newLocation != ps4->getPosition())
direction.invert(); //collision detected so change direction
// I know the above does not make the ball bounce but just to test this
// code I am seeing if I can send the ball back in the direction it came
}
Thanks for any help!