collision problem

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
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

collision problem

Post by Cleves »

Hey,

I've got a problem with collison. I've probably didn't understand how to put it all right, i've searched the forum and read the tutorial and yet could'nt solve it.

I've got 2 nodes. 1 is a map and the other is a player. I just want to create a collison between the player and the level.

Here's my code:

Code: Select all

IMetaTriangleSelector* mainTriangleSelector = 0;
mainTriangleSelector = smgr->createMetaTriangleSelector(); 
IAnimatedMesh* mesh = smgr->getMesh("Data/level.3ds");

if (mesh)
		node = smgr->addOctTreeSceneNode(mesh->getMesh(0));

if(node)
{

node->setPosition(vector3df(0,0,0));
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMaterialFlag(EMF_TRILINEAR_FILTER , true);
node->setMaterialFlag(EMF_FOG_ENABLE, true);
ITriangleSelector* s =  smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128); 
node->setTriangleSelector(s);
mainTriangleSelector->addTriangleSelector(s);
s->drop(); 
}


IAnimatedMesh* mesh2 = smgr->getMesh("Data/player.3ds");

if(mesh2)
  node2 = smgr->addOctTreeSceneNode(mesh2->getMesh(0));

if(node2)
{
node2->setPosition(vector3df(-40,-29,0));
node2->setMaterialFlag(EMF_LIGHTING, true);
node2->setMaterialFlag(EMF_TRILINEAR_FILTER , true);
ITriangleSelector* s2 = smgr->createTriangleSelectorFromBoundingBox(node2);
node2->setTriangleSelector(s2);
mainTriangleSelector->addTriangleSelector(s2);
s2->drop(); 
}
Any idea what's wrong here?

Thanks
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

*bump*
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

Can you describe your problem in more detail?

I think, it is not a good idea to add both the level-triangleselector and the player-triangleselector
to the metaselector. But because i don't know what you want to do and what happens, maybe the problem lies somewhere else...
It has long been an axiom of mine that the little things are
infinitely the most important.
-- Sir Arthur Conan Doyle, "A Case of Identity"
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Well, problem is that no collision occures between this objects. The player goes through the level walls with no problem.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

When I'm trying to use your function, it gives me an error:
'createTriangleSelectorFromBoundingBox' : undeclared identifier
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Cleves wrote:When I'm trying to use your function, it gives me an error:
'createTriangleSelectorFromBoundingBox' : undeclared identifier
Try smgr->createTriangleSelectorFromBoundingBox(...)
It is like it is. And because it is like it is, things are like they are.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Yes, exactly. Thanks jox.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

Can you please explain to me how this thing works? And how exactly I integrate it into the project.Thanks.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

At first some basic things:
What is needed for collision?
- selector for first node
- collision respone animator for second node with parameter like pointer to selector for other node. /See collision example/

Well, if you have many nodes you must use meta triangle selector like parameter. In this meta selector you must add selectors for all nodes, with which your node must collide. In this case your node will collide with all nodes which selectors are in meta triangle selector. This collision is of type "one to all".

If you want to make collision of type "all to all", when each node must collided with every node, you can use my function.
In this case you must first add meta triangle selector which return this function to each one node. And second - to create collision respone animator to each one s node with correspondent meta triangle selector.

Or if you have 10 nodes - you need 10 meta triangle selectors and 10 collision respone animators for full collision of this type. Just use any loop for this.

About your code
- you have not any collision respone animator, therefore you have not any collision. Create one for your player
- don't add player in meta triangle selector, because will get auto collision
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
Post Reply