Collision detection not working

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
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Collision detection not working

Post by Endar »

Okay, I'm sure that some of you might be sick of seeing my threads, but i'm doing bits of everything. :D My dad told me that I had to learn to multi-task :D

Okay, I have a quake level loaded (from the tuts) and I'm trying to add collision detection (the same from the tuts) to a model. I also have a FPS camera that is free, so I want to be able to go around with my FPS camera that has no collision detection and look at the model that has collision detection.

Code: Select all

bool loadMD2(video::IVideoDriver* driver, scene::ISceneManager* smgr, char* model_name, char* texture_name, 
			 scene::ISceneNode* node, scene::ITriangleSelector* selector)
{
	// Load md2 model
	scene::IAnimatedMesh* mesh = smgr->getMesh(model_name);
	scene::IAnimatedMeshSceneNode* model_node = smgr->addAnimatedMeshSceneNode(mesh);
	
	// Load texture
	if(model_node){
		model_node->setMaterialFlag(video::EMF_LIGHTING, false);	
		model_node->setMaterialTexture(0, driver->getTexture(texture_name) );
		// Set animation
		model_node->setMD2Animation(scene::EMAT_STAND);

		// Get radius of model for collision detection
		core::aabbox3d<f32> box = node->getBoundingBox();
        core::vector3df radius = box.MaxEdge - box.getCenter();

			scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( selector, model_node
			, core::vector3df(30,50,30), core::vector3df(0,-100,0), 100.0f, core::vector3df(0,50,0) );
		model_node->addAnimator(anim);
		anim->drop();

	}
	

return false;
}
This code works perfectly when I change "model_node" to "smgr->getActiveCamera()" to assign collision detection to the FPS camera. But when I leave it as is and try and set collision detection to the md2 model, the model just stays in one spot, which is above the ground. I assumed that with collision detection the model would immediatly fall to the ground after everything was loaded.

Am I wrong in this assumption, or is there something wrong with my code?
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Collision Detection <> Physics (gravity, ...)

For the kind of things you want you'll need a physics engine (Newton, ODE, ...)

Mod: gravity would work but if you want the body to fall realistic then you'll need ragdoll
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

But, there is a basic collision detection system in Irrlicht.

Somewhere around the forums is a thread about a guy who wrote a 3rd person camera. There, he has the collision detection working for a model.

Which reminds me, I should go and read that.....
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Endar wrote:But, there is a basic collision detection system in Irrlicht.

Somewhere around the forums is a thread about a guy who wrote a 3rd person camera. There, he has the collision detection working for a model.

Which reminds me, I should go and read that.....
Yes, there is a collision detection system in Irrlicht. But I was aiming at your "body-falls-on-the-ground" part :wink:
lobbin
Posts: 11
Joined: Wed Jun 02, 2004 1:41 pm
Location: Sweden
Contact:

Post by lobbin »

Endar wrote:But, there is a basic collision detection system in Irrlicht.

Somewhere around the forums is a thread about a guy who wrote a 3rd person camera. There, he has the collision detection working for a model.

Which reminds me, I should go and read that.....
Please let me know if you find this thread, this is exactly the same problem I've having.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

:D

Found it!!

http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=961

And, I changed the code a bit. It was not completely to my liking. He had the mouse inverted on both the X and Y axis, and the whole bounding box thing was wierd, so I got rid of it and the cursor just stayes in the middle of the screen. :D
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

bal wrote: Yes, there is a collision detection system in Irrlicht. But I was aiming at your "body-falls-on-the-ground" part :wink:

Yeah, but when you do collision detection with a FPS camera, you can specify gravity and all that and the camera will fall to the ground. :D
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
lobbin
Posts: 11
Joined: Wed Jun 02, 2004 1:41 pm
Location: Sweden
Contact:

Post by lobbin »

Endar wrote: Yeah, but when you do collision detection with a FPS camera, you can specify gravity and all that and the camera will fall to the ground. :D
Any idea my collision isn't working when I use it on an animated-mesh instead of a camera? gravity is working on the mesh, just not collision.
Post Reply