Public Group

# Collision problem

This topic is 2768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I´m facing a problem wen i try to know wen a bullet and a hero collide. can someone help plz?
the code is this :

 bool bala=false; float xptocontador=0; float destino[3]; float origem[3]; float posbullet[3]; void drawBala(){ bala = true; float d1 =calculardistancia(posb,post); // calc position between hero and tower float d2 =calculardistancia(posb,posbullet); // calc position between hero and bullet printf("###########-pos boneco %f %f %f-########\n",posb[0],posb[1],posb[2]); // test purpose printf("**********dist bala %f -**********\n",d2);// test purpose if((int ) xptocontador==5||calculardistancia(posb,posbullet)==0){ // if bullet reach the end of range or the hero sop the draw bala= false; xptocontador=0; } else{ glPushMatrix(); glTranslatef(0,1,0); glRotatef(atan2(post[0]-destino[0],post[2]-destino[2])*(180/3.14)-0.8*(180/3.14),0,1,0); // rotate bullet to hero glTranslatef(post[0]-destino[0]-((post[0]-destino[0])+xptocontador),0,post[2]-destino[2]-((post[2]-destino[2])+xptocontador)); // move bullet to heroe glColor3f(0.8f, 0.5f, 2.0f); glutSolidSphere(0.6,30,30); printf("ttttttttttt-xpto %f-tttttttttttttttttttt\n",xptocontador); glPopMatrix(); xptocontador+=0.01; posbullet[0]=post[0]-destino[0]-((post[0]-destino[0])+xptocontador); // save position of bullet posbullet[1]=post[1];// save position of bullet posbullet[2]=post[2]-destino[2]-((post[2]-destino[2])+xptocontador);// save position of bullet printf("###########-pos bullet %f %f %f-########\n",posbullet[0],posbullet[1],posbullet[2]); } } void drawTorre(float m,float rtorre,float n){ glColor3f(1.0f, 2.0f, 0.0f); glPushMatrix(); glTranslatef(0, coiso*distancia*escala,-10); post[0]=0; post[1]= 0; post[2]=-10; float d =calculardistancia(post,posb); if(d<=5)// test if hero is in the range { if(bala == false){ // if there is no bullet start a new one with the actual position of the hero glPushMatrix(); destino[0]=posb[0]; destino[1]=posb[1]; destino[2]=posb[2]; drawBala(); glPopMatrix(); } } if(bala == true){ // if bullet is already drow, continue till bala = false drawBala(); printf("#########-Bullet on-###########\n");} printf("vvvvvvvv-%f-vvvvvvv\n",d); glRotatef(atan2(post[0]-posb[0],post[2]-posb[2])*(180/3.14),0,1,0); for(int i=0;i<ndonuts;i++){ glPushMatrix(); glRotatef(90,1*escala,0,0); glutWireTorus(raiointrior,raioexterior,numlados,aneis); glPopMatrix(); glTranslatef(0, coiso*distancia*escala, 0); } //Bule de chá glTranslatef(0, coiso*distancia*escala-0.2, 0); glRotatef(90,0,1,0); glRotatef(-45,0,0,1*escala);//Incliar bool glColor3f(0.0f, 1.0f, 0.0f); glutSolidTeapot(tamanhobule); //Cria bule glPopMatrix(); } 

The bullet moves to the hero and stop wen reaches the range. Some tip? :S i´m using c++ in visual studio with opengl

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633649
• Total Posts
3013117
×