Character falling through terrain while walking/running

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Character falling through terrain while walking/running

Post by red82 »

I just implemented the new terrain scene node in my 3rd person game. I used to be using the libmini. That worked alright, but I my character (sydney) would sometimes walk part way through hills. With this new scene node it seems better, but If I take a few steps, she falls endlessly through the terrain. These "holes" appear to be in the same spots ever time I run it so I think it may be something with the triangle selector?. If I adjust the dimensions and make her float way above the ground, then it is fine, no noticable drops while running. Any Ideas? Thanks.

Here is the code for the triangle selector:

Code: Select all

	terrainSelector= smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(terrainSelector);
	terrainSelector->drop();
Here is the code I use for my collision.

Code: Select all

irr::core::vector3df avatarDimensions = avatarMesh->getBoundingBox().MaxEdge - avatarMesh->getBoundingBox().MinEdge;
	
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		terrainSelector, avatarNode, avatarDimensions/2.0f,
		core::vector3df(0,-100.0f, 0), 
		core::vector3df(0,0,0));
avatarNode->addAnimator(anim);
	
anim->drop();
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Are you scaling the terrain after creating the triangle selector?
Image
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

nope, I scale it right when I create the terrain, way before I do anything else

Code: Select all

terrain = smgr->addTerrainSceneNode( "textures/landscape/heightmap.jpg");

	terrain->setScale(core::vector3df(40, 4.4f, 40));
	terrain->setMaterialFlag(video::EMF_LIGHTING, false);

	terrain->setMaterialTexture(0, driver->getTexture("textures/landscape/colormap.jpg"));
In wireframe mode I do not see any holes or anything that would cause any holes like this either.

I do use the camera from http://irrlicht.sourceforge.net/phpBB2/ ... er&start=0
think that may have something to do with it?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

The only thing I see that is more efficient, is instead of calculating the radius of the node by MaxEdge - MinEdge and then dividing by 2.0, just get the radius from MaxEdge - Center.

I don't see anything wrong with that code. The camera node shouldn't be affecting this at all, as your collision is based off of your avatarNode, not the camera. Well, I didn't look at that camera code, but if the camera code is modifying the position of the node it's following, like the avatar node, this may be causing a problem. When I get a chance, I'll look at that camera code, or you could email me your camera class, so I could look at it, email's in my profile.
Image
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

OK, I sent ya the camera class I am using. Also I tried using MaxEdge - Center and it does the same thing.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Yeah, it does the same thing, but it saves you a calculation, you don't have to divide by 2 to get the radius. I emailed you back about the camera class you're using and how it is affecting the position of the node.
Image
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

hmm, I don't think it was a problem with that camera class afterall.... I completley removed it and tried it with a camera from http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3542 and created a new event reciever that moved the model on the x axis forward when i hit a key. This is completley differerent from the camera class I sent you, this camera class does not change the avatar's node at all, but yet it still falls through.

I then tried removing all those camera classes all together and try it with a FPS camera... it did it to that too...

so now i went back to the actual tutorial.... as it was, i added sydney to it. I added to the listener so that she moved forward again if a key was pressed... boom,, she fell through.... If I give the FPS camera gravity, and the same "boundingbox" as sydney for collison, it falls through as well....

I think if anything that is resting directly on top and moves may fall through and this may be a bug in the terrain class??? Unless I am doing something completley wrong, but as far as I can tell, I have my characters bounding box for collision set right... she looks like she is on the ground right, isn't floating or half way in the terrain.... no outside classes are tampering with the node position....

Has anyone successfully moved a mesh around at all on the new terrain class implemented in 0.9??? If so any hints?
dopyiii
Posts: 26
Joined: Wed Mar 23, 2005 7:48 pm

Post by dopyiii »

I haven't had this problem, but I have had another weird problem walking on terrain: every now and again you get "stuck". The heightmap that I'm using doesn't have any sharp edges or anything - it looks really good.

I tried adjusting the falloff (?) value (I can't remember to what it's a parameter, but I just remember it's the last one :? ) and every now and again the camera "hops", but doesn't get stuck as often. It also seems to help if I look up a little and not down at the terrain.

I know this really isn't directly related to your problem (or a solution to it), but maybe there's some problem with the terrain scene node and the collision animator...:?:
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

Actually I think it is linked to it,,, because I have noticed getting stuck in places too, but then if I switch directions a couple times to "wiggle free" she will fall through.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I'm still thinking about this as much as I can. I almost always use a 3rd party physics engine now for even basic collision, as it's much faster and more accurate. I'll need to dig through the code again, when I get time ( busy with looking for a new job, just got a new puppy and been playing a new MMO recently that's been taking up a lot of time )
Image
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

Ok, thats cool... In the mean time I think I might try to get newton working with it, I tried it once, but failed miserably...(even though I didn't try too hard). I'll let ya know how that goes this weekend.
dopyiii
Posts: 26
Joined: Wed Mar 23, 2005 7:48 pm

Post by dopyiii »

Spintz, aren't you looking at like a billion things for people... including myself? :wink:

Red, if you get Newton working, would you enlighten me on how to use it for the terrain collision gravity thing? I've considered Newton, but I didn't take the time to really give it a good once over (school + America's Army + sleep != free time :shock: )
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Yes, but it's ok, I enjoy it and I learn more as I go, I might just need to slow down a bit with so much going on, but I consider the terrain a priority, since I had originally developed it. :)
Image
red82
Posts: 13
Joined: Fri Jan 14, 2005 3:38 am

Post by red82 »

And we are greatful for it!! :D :D :D
dopyiii
Posts: 26
Joined: Wed Mar 23, 2005 7:48 pm

Post by dopyiii »

Absolutely! :D
Post Reply