Collision with wall

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
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Collision with wall

Post by NightCrawler »

Hi,
is this possible to collide a NPC with walls? I used; "createTriangleSelectorFromBoundingBox", but it is not colliding :cry: .
kindly help. my NPSs dissapear suddenly when they r near walls.
Quillraven
Posts: 62
Joined: Fri Aug 22, 2008 7:22 am

Post by Quillraven »

1) try to use the search function :) there are tons of collision threads

2) one (my) solution for this problem can be like this:

normally you save your nps in an array/list/vector or sthg. like that and in every mainloop you update all npcs. so you write your own update function and do the collision checking there.

here is an example:

Code: Select all

/*
 * function:	Update
 * params:		None
 * return:		Nothing
 * purpose:		updates the cart's position
 */
void Cart::Update()
{
	core::vector3df newpos;
	float fAlpha = node->getRotation().X * DEGTORAD;
	float fBeta = node->getRotation().Y * DEGTORAD;
	float fDelta = FRAMEWORK->GetElapsed();
	static core::vector3df direction;
	static core::triangle3df triout;
	static bool fallout = true;
	static const scene::ISceneNode* outNode;
	static core::vector3df collpos;
	const float gravity = 100.0f*fDelta;

	// reduce speed when player doesn't accelerate
	if( fSpeed > 0 )
		fSpeed = max( 0.0f, fSpeed - 10.0f * fDelta );
	else if( fSpeed < 0 )
		fSpeed = min( 0.0f, fSpeed + 10.0f * fDelta );

	direction.X = fDelta * fSpeed * cos( fBeta ) * cos( fAlpha );
	direction.Y = fDelta * fSpeed * sin( fAlpha ) - gravity;
	direction.Z = fDelta * -fSpeed * cos( fAlpha ) * sin( fBeta );
	newpos = smgr->getSceneCollisionManager()->getCollisionResultPosition(	world,							// triangleselector of world
																			node->getAbsolutePosition(),	// position of node
																			core::vector3df( 10, 20, 10 ),	// collellipsoid of node
																			direction,						// direction force to move
																			triout,							// collision triangle
																			collpos,						// collision point
																			fallout,						// ?
																			outNode,						// collision node
																			0.01f );							// slide factor
	node->setPosition( newpos );
}	// end Update

in your program you have sthg like this:

Code: Select all

int main()
//...
list<NPC*> npcs;
npcs.push_back( new NPC() );

//...
while( gameisrunning )
{
  list<NPC*>::iterator itnpc = npcs.first()
  while( itnpc != npcs.empty() )
  {
    (*itnpc)->Update();
    itnpc++;
  }

  beginScene( true, true );
  // ...
  endScene();
}
//...
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Post by NightCrawler »

Ya thanks, i assumed that NPC problem is solved(or about to be solved), but is it possible to collide a node with the main map using "createTriangleSelectorFromBoundingBox" :? . if possible could u kindly give me just a clue, how to do that :) .
I Hate Those, Who Like To Sleep.
Quillraven
Posts: 62
Joined: Fri Aug 22, 2008 7:22 am

Post by Quillraven »

http://irrlicht.sourceforge.net/docu/example015.html

the idea is to "register" all scenenodes's triangleselectors in one triangleselector (your world).

when u now create a collisionresponseanimator, you tell it, what your world looks like (the triangleselector) to do the collision by the engine.

check the part, when the tutorial enums all scenenodes. it creates specific triangleselectors for specific scenenodes. the player himself (in the example a camera) then just needs the collisionresponseanimator.
NightCrawler
Posts: 20
Joined: Thu Nov 05, 2009 11:36 am

Post by NightCrawler »

thanks :D .
I Hate Those, Who Like To Sleep.
Post Reply