Hi. I hope help me with a trouble of collisions. Here my code:
the first time (before return to start position) , all work fine:
http://img129.imageshack.us/img129/9248/img1kb5.th.jpg
after return to start position, laser collides with enemy, but enemy is in another side :-(
http://img353.imageshack.us/img353/4147/img2jf1.th.jpg
What´s wrong. :-(
Thank you very much to help me. :-)
Graphics3D 640,480,16,1 SetBuffer BackBuffer() Const FPS=60 global rayo,platillo,enem,metal,secuencia x_flot1=0 y_flot1=-0.25 camara=CreateCamera() CameraRange camara,0.05,10 luz=CreateLight() platillo=LoadAnimMesh("platillo.b3d") ScaleEntity platillo,0.04,0.08,0.08 RotateEntity platillo,0,90,0 PositionEntity platillo,0,-0.2,0.5 ExtractAnimSeq(platillo,0,40);Secuencia 1 ExtractAnimSeq(platillo,40,60);Secuencia 2 secuencia=1 animate platillo,1,1,secuencia,0 rayo=loadsprite("rayo.bmp") hideentity rayo enem=loadmesh("enemigo.b3d") hideentity enem metal=loadtexture("metal.bmp") If KeyHit(32) Then crea_disparo() SoundVolume sonido_laser,0.5 PlaySound sonido_laser endif Type disparo Field tipo Field vel# End Type Function crea_disparo() ray.disparo=New disparo ray\tipo=CopyEntity(rayo) ScaleSprite ray\tipo,0.02,0.02 EntityType ray\tipo,1 EntityRadius ray\tipo,0.02 If secuencia=1 Then PositionEntity ray\tipo,EntityX(platillo)+0.05,EntityY(platillo)+0.015,EntityZ(platillo) ray\vel=0.05 ElseIf secuencia=2 Then PositionEntity ray\tipo,EntityX(platillo)-0.05,EntityY(platillo)+0.015,EntityZ(platillo) ray\vel=-0.05 EndIf End Function Function mueve_destruye_disparo() For ray.disparo=Each disparo MoveEntity ray\tipo,ray\vel,0,0 If EntityX(ray\tipo)>EntityX(platillo)+1 Or EntityX(ray\tipo)<EntityX(platillo)-1 Then FreeEntity ray\tipo Delete ray EndIf Next End Function Function destruye_disparo() For ray.disparo=Each disparo If EntityCollided(ray\tipo,3) Then FreeEntity ray\tipo Delete ray EndIf Next end function Type flotilla1 Field tipo Field vel# End Type Function crea_flotilla1() For i=1 To 5 flot1.flotilla1=New flotilla1 x_flot1=Rnd(1,2)*p_flot1 flot1\tipo=CopyEntity(enem) ScaleEntity flot1\tipo,0.08,0.08,0.08 PositionEntity flot1\tipo,x_flot1,y_flot1,0.5 EntityTexture flot1\tipo,metal,0,1 NameEntity flot1\tipo,i EntityType flot1\tipo,3 EntityBox flot1\tipo,-0.04,-0.04,-0.04,0.08,0.08,0.08 y_flot1=y_flot1+0.1 flot1\vel=0.01*v_flot1 v_flot1=v_flot1*-1 p_flot1=p_flot1*-1 Next End Function crea_flotilla1() Function repos_flotilla1() For flot1.flotilla1=Each flotilla1 If EntityX(flot1\tipo)>0.6 Or EntityCollided(flot1\tipo,1) Then If EntityName(flot1\tipo)=1 Then PositionEntity flot1\tipo,Rnd(-1.3,-0.6),-0.25,0.5 EndIf If EntityName(flot1\tipo)=3 Then PositionEntity flot1\tipo,Rnd(-1.3,-0.6),0,0.5 EndIf If EntityName(flot1\tipo)=5 Then PositionEntity flot1\tipo,Rnd(-1.3,-0.6),0.25,0.5 EndIf EndIf If EntityX(flot1\tipo)<-0.6 Or EntityCollided(flot1\tipo,1) Then If EntityName(flot1\tipo)=2 Then PositionEntity flot1\tipo,Rnd(1.3,0.6),-0.125,0.5 EndIf If EntityName(flot1\tipo)=4 Then PositionEntity flot1\tipo,Rnd(1.3,0.6),0.125,0.5 EndIf EndIf Next End Function Function mueve_flotilla1() For flot1.flotilla1=Each flotilla1 MoveEntity flot1\tipo,flot1\vel,0,0 Next End Function period=1000/FPS time=MilliSecs()-period Collisions 1,3,3,1 While Not KeyHit(1) Repeat elapsed=MilliSecs()-time Until elapsed ticks=elapsed/period tween#=Float(elapsed Mod period)/Float(period) For k=1 To ticks repos_flotilla1() If k=ticks Then CaptureWorld time=time+period mueve_flotilla1() mueve_destruye_disparo() destruye_disparo() updateworld next RenderWorld tween Flip wend End
the first time (before return to start position) , all work fine:
http://img129.imageshack.us/img129/9248/img1kb5.th.jpg
after return to start position, laser collides with enemy, but enemy is in another side :-(
http://img353.imageshack.us/img353/4147/img2jf1.th.jpg
What´s wrong. :-(
Thank you very much to help me. :-)