Collision detection hitting invisible walls

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
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Collision detection hitting invisible walls

Post by scgtrp »

I'm attempting to implement collision detection into my testing program (a game about walking around on a flat planet, and trying not to get bored enough to jump off the edge of it). I've noticed a few problems:

- If gravity is too small, the camera doesn't fall at all.
- If I set gravity to -5 or so, the camera falls, but after it hits the ground it can't move (aside from shifting around .0001 unit or so). It's almost as if my planet is made of industrial strength glue which dries as soon as you touch it.
- The camera's X position seems to be changing of its own will. I don't have anything in my code to change it, yet by the time I fall to the planet it goes from 0 to 1.77. Z doesn't change at all.
- If too much of the ground goes out of the window, the whole thing will disappear. Is this some kind of culling, and can I turn it off?

My code (apologies for long post, but pastebin wasn't cooperating and told me I was attempting to do SQL injection or some crap):

Code: Select all

#include <Main.hpp>

int main()
{
	device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 32, false, true, false);
	if (!device) return 1;
	
	device->getFileSystem()->addFolderFileArchive("data/");
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();
	
	IAnimatedMesh* world = smgr->getMesh("models/planets/flat.x");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(world);

	camera = smgr->addCameraSceneNodeFPS(NULL, 100.0, 5.0);
	camera->setPosition(vector3df(0, 10, 0));
	ITriangleSelector* selector = smgr->createTriangleSelector(world, node);
	node->setTriangleSelector(selector);
	ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, camera, vector3df(5, 5, 5),
		vector3df(0, -5, 0), vector3df(0, 0, 0));
	camera->addAnimator(anim);
	anim->drop();
	
	device->setWindowCaption(L"");

	device->getCursorControl()->setVisible(false);

	sun = smgr->addLightSceneNode(NULL, vector3df(50, 50, 50), SColor(255, 128, 128, 64));
	
	IGUIStaticText* fpslabel = guienv->addStaticText(L"", rect<int>(10, 10, 200, 32), true);
	fpslabel->setDrawBorder(false);
	fpslabel->setOverrideColor(SColor(255, 255, 255, 0));
	int fps, last_fps = -1;
	
	while(device->run())
	{
		driver->beginScene(true, true, SColor(0, 0, 0, 24));
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
		
		vector3df pos = camera->getPosition();

		fps = driver->getFPS();
		if (fps != last_fps)
		{
			stringw s = stringw(fps) + L" FPS, X=" + stringw(pos.X) + " Y=" + stringw(pos.Y) + " Z=" + stringw(pos.Z);
			fpslabel->setText(s.c_str());
			last_fps = fps;
		}
	}
	
	device->drop();
	return 0;
}
Main.hpp is just a couple of #includes and a pile of using namespace ...; lines. flat.x is a 20x20x1 cylinder made in blender, exported to .x format with 'swap zy', 'flip z', and 'no smooth' turned on (I figured the smoothing might be making the surface curved somehow, which was throwing off the collision detector. That wasn't it.) Let me know if you need that file, hopefully my webserver will be back up by then (whee, everything breaking at once...)
scgtrp
Posts: 16
Joined: Sun Jun 15, 2008 1:25 am

Post by scgtrp »

After poking around on the forum I noticed a few people said .x loading was buggy. Just tried 10 or so other formats - some do the same thing as .x, while others let me go straight through the ground.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

*BUMP*

RE: "invisible walls"

Is this a (known) Irrlicht bug? has anyone else experienced it and found the cause?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The original post doesn't seem to have much, if anything, to do with "invisible walls". Since we never got to see the "flat.x" model, we'll never know.

Now, how about you explain your problem, and we'll see if we can work it out.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Collision detection hitting invisible walls

Post by Acki »

scgtrp wrote:flat.x is a 20x20x1 cylinder made in blender, exported to .x format with 'swap zy', 'flip z', and 'no smooth' turned on
it's always a good idea to provide the mesh(es) for testings, especially when the problem seems to depend on them...
not everyone can reproduce them 100%... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Meh, I have been browsing the forum archives for a long time and my brain is a stew. Maybe I confused this with another topic, I did see similar problems that were unsolved.

I tried to phrase my post to avoid such a response, it was just meant to be a quick query; this is a can of worms I am not sure I really want to open. My usual approach is to use ODE, but this application didn't really need it. My attempt at keeping things simple appears to have failed.

Also this is for a university project, so I shouldn't really be putting bits on the internet just yet.

But it's just the prototype so I suppose it doesn't matter...

The problem: invisible walls. So how do I explain that better?

The environment is an arena with no floor (I removed that in case it was somehow colliding there). It's essentially 2D, so everything moves in the one plane. It's all a single animated mesh node: one big arena wall, with several boxes scattered in it, loaded from a single .b3d file

http://xzist.org/temp/walls.b3d

So I have little entities that move around in the arena, and can't escape it or penetrate the boxes. But they sometimes get stuck as if against an invisible wall in an empty space where there should be no triangles.

Collisions that are supposed to happen seem to be correct, so it's not as if the collision mesh has somehow got orientated differently to what is displayed. If that could ever even happen!

I also tried an FPS camera with collision response, and I can hit these walls with that too.

Here's some snippets of that...

Code: Select all

		scene::ICameraSceneNode *camera = engine.getSceneManager()->addCameraSceneNodeFPS(0, 200.0, 1.0);
		camera->setPosition(core::vector3df(0,4.f,0));
		camera->setTarget(core::vector3df(1,0,0));
		camera->setNearValue(0.01);
		camera->setFOV(core::PI/2.5);

		scene::IAnimatedMeshSceneNode *wallNode = engine.getSceneManager()->addAnimatedMeshSceneNode(
			engine.getSceneManager()->getMesh("walls.b3d")
			);
		
		collisionTriangles = engine.getSceneManager()->createOctTreeTriangleSelector(
			wallNode->getMesh()->getMesh(0), wallNode, 1);

		scene::ISceneNodeAnimator *anim = engine.getSceneManager()->createCollisionResponseAnimator(
			collisionTriangles, camera,
			core::vector3df(1,1,1)*0.05,
			core::vector3df(0,0,0), 
			core::vector3df(0,0,0),
			0.f);
		camera->addAnimator(anim);
		anim->drop();
I'm using an octtree as the problem seems even more apparent without. Putting the node size to 1 also helped improve it a lot, but it does still occur in certain places. Putting “slidingValue” to 0 also seemed to help a bit, maybe letting them slide over whatever invisible obstacles there are.

Well, that's all I can think of to post right now. If there's anything else that would help tell me.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Insufficient data for meaningful answer.

It's not a problem that I'm aware of. I'm sure that you are seeing it happening, but I think it's going to take a debugger (or Vitek's telepathy) to diagnose it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

I made a small example to test it. (here, along with walls.b3d).

And while doing so I found out an interesting thing: I only get this problem on Linux :S On windows it is fine.

Both tests were with Irrlicht 1.4.2.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Update:

When compiled in debug mode it also works on Linux.

So it doesn't work when compiled with the NDEBUG flag.

A search gives this unresolved post which seems similar.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Oops. I'm between Lunix installs at the moment, so I can't test that. Thanks for the report though; if it's definitely replicatable, then it would be great if you could start a new thread over in the bugs forum.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply