thanks roger,
1)i am using 2 camera's, but only one camera is targeting
2)yes u are right there is no need to check 2 time but it is not wrong to check 2 times.when i am debuging i just wrote it.
main while loop
Code: Select all
while(device->run() && driver)
{
//main update fn
myupdate::update(); // funtion enemy position and fire
driver->beginScene(true,true,0);
smgr->drawAll();
//below camera fireand checking enemy
line.start=pointer->getAbsolutePosition();
line.end = line.start-(camera->getTarget() - line.start).normalize()*800.0f ;
scene::ISceneNode *chk=smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(line,8);
core::stringw str="Camera-X=";
//rp->lm is for mouse ckick
if((chk)&&(rp->lm==1))
{
if((chk->getID()& 8)==8)
{
if (smgr->getSceneCollisionManager()->getCollisionPoint(line,killselector,intersection,tri))
{
// for blood particals
scene::IParticleSystemSceneNode *ps=smgr->addParticleSystemSceneNode(false,0,-1,intersection);
ps->setParticleSize(core::dimension2d<f32>(20.0f,20.0f));
scene::IParticleEmitter *em=ps->createBoxEmitter(core::aabbox3d<f32>(-5,-5,-5,5,5,5),core::vector3df(0.01f,0.01f,0.01f),
100,120,video::SColor(0,255,255,255),video::SColor(0,255,255,255),800,1000,20);
ps->setEmitter(em);
em->drop();
scene::IParticleAffector *paf=ps->createGravityAffector(core::vector3df(0.0f,-0.01f,0.0f),1000);
ps->addAffector(paf);
paf->drop();
ps->setMaterialFlag(video::EMF_LIGHTING, false);
ps->setMaterialTexture(0, hitimg);
ps->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
scene::ISceneNodeAnimator *anim=smgr->createDeleteAnimator(1000);
ps->addAnimator(anim);
anim->drop();
}
}
}
rp->lm=0;
//below is for the line drawing only
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->setMaterial(lineMaterial);
driver->draw3DLine(line.start,line.end,video::SColor(0, 255,0,0));
line.start=killer[0]->getPosition();
line.end=camera->getPosition();line.start.Y=40;
driver->draw3DLine(line.start,line.end,video::SColor(0, 0,0,255));
line.start=killer[1]->getPosition();line.start.Y=40;
line.end=camera->getPosition();
driver->draw3DLine(line.start,line.end,video::SColor(0, 0,255,0));
driver->endScene();
}
driver->drop();
return 0;
}
funtion of update
i put all the enemys data in single linked list (datastructure ex:struct node t1) only data.
Code: Select all
void myupdate::update()
{
tick *t1;
t1=st; //st holds 1st address of linked list
f32 a=0,b=0;
bool fire=false;
core::line3d<f32> geta;
while(t1!=NULL)
{
scene::IAnimatedMeshSceneNode *man;
u8 in=(t1->id-8);
man=killer[in]; [b] //killer[] is enemys nodes[/b]
f32 z=man->getPosition().Z;
f32 x=man->getPosition().X;
geta.start=man->getPosition();
geta.start.Y=50;
geta.end=camera->getPosition();
////////////////kil returns 32 when i am back 0 when i am front////////
scene::ISceneNode *kil=smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(geta,32);
if(kil)
{
if(kil->getID()==32)
{
fire=true;
t1->fire=true;
}
else
t1->fire=false;
}
/////////////////////////
if((t1->j==0)&&(t1->k==0))
{
f32 y;
u8 pos=rp->postion(man->getPosition());
s8 campos=rp->postion(camera->getPosition());
s8 tgt=t[pos][campos];
tick *t2=st;
while(t2!=NULL)
{
//2 enemy's will not stand at same place
if(((t2->tgt==-1)&&(tgt==t2->pos))||(t2->tgt==tgt))
{
tgt=-1;
break;
}
t2=t2->next;
}
t1->pos=pos;
t1->tgt=tgt;
t1->j=1;
t1->k=1;
[//below code is to just move enemy to the camera x-axis and z-axis
//to find the exact where the camera and rotatation deg
if(tgt!=-1)
{
a=(ax[tgt]-x);
b=(az[tgt]-z);
if((az[tgt]!=(int)z)&&(ax[tgt]!=(int)x))
y=(atan2(a,b)*(180/(float)3.14159265));
else if (ax[tgt]==(int)x)
{
if(az[tgt]>z)
y=0;
else
y=180;
}
else if(ax[tgt]>x)
y=90;
else
y=-90;
t1->y=y;
}
}
s16 tgt=t1->tgt;
a=abs(ax[tgt]-x);
b=abs(az[tgt]-z);
//moves x-axis and z-axis closer to camera
if((i==4)&&(tgt!=-1))
{
if(stpt>20)
stpt=0;
else
stpt+=(f32).4;
if((t1->j!=0)&&(b>=a))
{
if(az[tgt]==(int)z)
t1->j=0;
else if(az[tgt]>man->getPosition().Z)
z+=(f32)1.0;
else
z-=(f32)1.0;
b=b-t1->j;
}
if((t1->k!=0)&&(a>=b))
{
if(ax[tgt]==(int)x)
t1->k=0;
else if(ax[tgt]>man->getPosition().X)
x+=(f32)1.0;
else
x-=(f32)1.0;
a=a-t1->k;
}
man->setPosition(core::vector3df(x,5,z));
man->setCurrentFrame(stpt);
man->setRotation(core::vector3df(0,t1->y,0));
}
else
{
t1->j=0;
t1->k=0;
}
t1=t1->next;
}
//here the enemy fire
if(fire==true)
rp->fire(8);
}
i hope it will help u
main point
only if i press key-6(i==4) the enemy will start following camera and shoot. until i press key-6 they will not move
this for my convenience i wrote
if enemy is not moving problem appears.
if enemy moves there is no problem most of the time.
but my point is when i am back getSceneNodeFromRayBB(kil=32) returns 32 if i move front it returns 0(when enemy is not move)
in game enemy will move so i think they will be no problem.but still why i get this problem i didn't understand?
its difficult to understand my code and respond i just paste some imp code only i think i will help u
thanks once again for helping me