what i'm doing bad in this collision detection?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
saulotmalo
Posts: 54
Joined: Wed Oct 04, 2006 6:56 am

what i'm doing bad in this collision detection?

Post by saulotmalo »

i think i did it well but... here is some code if anyone can help me out how to solve it... well...

Code: Select all

    //first insert a square wich will be the wall (1.0 ver )
    node = smgr->addTestSceneNode();
    node->setScale(core::vector3df(1,20,1));
    node->setPosition(core::vector3df(130,-105,0));    
    select=node->getTriangleSelector(); //here i get the triangle selector to do the comparision ( or i think it works that way... )

....

   //this square will be moving arround the screen...
     scene::ISceneNode* node = 0;
    node = smgr->addTestSceneNode();
    node->setPosition(core::vector3df(30,-60,0));   

    core::vector3d<f32> start,end;

	while(device->run())
	{
        start=node->getPosition();
       node->setPosition(node->getPosition()+core::vector3df(0.1,-0.1,0));
       end=node->getPosition();

        core::vector3df colision;  
        core::triangle3df triangulo;
        core::line3d<f32> line(start,end);

     smgr->getSceneCollisionManager()->getCollisionPoint(line,select, colision,triangulo);


		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}
with this code i get the vector 0,0 :( so i think i have something don't working but i don't see it.. i've been using the API doc alot also i try to findo out what can be the problem. also the line is working, i think so because when i try to do the average point it is on the center.

By the way... the line height it is infinite? i mean.. it starts and ends when it does the test or have an start and end? ... i realy speak bad english :'(
funcdoobiest
Posts: 48
Joined: Thu Jun 15, 2006 6:35 pm

Post by funcdoobiest »

The line Height is not infinite, if the height your line is at is lower than the bottom of the wall it will miss. I guess you mean the vector line is (0,0,0), which means you are getting no collision.

getCollisionPoint returns true if you collide so first do this

Code: Select all

if(smgr->getSceneCollisionManager()->getCollisionPoint(line,select, colision,triangulo))
{
    //collision response etc.
    //if you do not reach this you have definitely not collided
}
beyond that you haven't really told us in what way it doesn't work. A guess would be that your test line is too small, it needs to be long enough to stick out of the box or the box will go half way through the wall before its notices, try putting end further away
saulotmalo
Posts: 54
Joined: Wed Oct 04, 2006 6:56 am

Post by saulotmalo »

thanks for the help :) your way of get how if there is a collision is pretty good :)

also i've been working and i've found the mistake it was that

select=node->getTriangleSelector();

doesn't lend you a triangle selector , it only return one if its atached to the node. also i've used a function that creates a triangle selector from a bounding box and it works...

now i'm getting a problem wich doens't know how to solve :( is this...

if i have a node box and it is hit by the ball.. then how can i tell the ball to be reflected? ... hard for me at least... but thanks to all people my game is looking better :)
Post Reply