Hi,
is this possible to collide a NPC with walls? I used; "createTriangleSelectorFromBoundingBox", but it is not colliding .
kindly help. my NPSs dissapear suddenly when they r near walls.
Collision with wall
-
- Posts: 62
- Joined: Fri Aug 22, 2008 7:22 am
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:
in your program you have sthg like this:
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();
}
//...
-
- Posts: 20
- Joined: Thu Nov 05, 2009 11:36 am
-
- Posts: 62
- Joined: Fri Aug 22, 2008 7:22 am
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.
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.
-
- Posts: 20
- Joined: Thu Nov 05, 2009 11:36 am