Help with collisions

Blitz3D Forums/Blitz3D Beginners Area/Help with collisions

I've heard about strange things happening with re-positioning and render-tweening although there have been a few good solutions posted if you do a search.



Nop, not is the command Render tween. Here is the code an can try you it.

;Javier Ramírez...

Graphics3D 640,480,16,1

SetBuffer BackBuffer()

Global platillo,txt_plat,x#,y#,v,p,disp

y=-0.3
v=1
p=-1

camara=CreateCamera()
CameraRange camara,0.01,10

luz=CreateLight()

platillo=CreateSphere()
ScaleEntity platillo,0.03,0.03,0.015
PositionEntity platillo,0,-0.18,0.5
;PositionEntity platillo,0,0.12,0.5

Type balas
  Field tipo
End Type 

Function crea_balas()
  bal.balas=New balas
  bal\tipo=CreateSphere()
  ScaleEntity bal\tipo,0.01,0.01,0.01
  PositionEntity bal\tipo,EntityX(platillo),EntityY(platillo),EntityZ(platillo)
  EntityType bal\tipo,1
  EntityRadius bal\tipo,0.01
End Function 

Function mueve_balas()
  For bal.balas=Each balas
      MoveEntity bal\tipo,-0.02,0,0
      If EntityX(bal\tipo)<-0.5 Or EntityCollided(bal\tipo,3) Then
         FreeEntity bal\tipo
         Delete bal
      EndIf 
  Next
End Function 

Function movimientos_disparo()

 ;If EntityY(platillo)<0.3 Then
 ;   If KeyDown(200) Then MoveEntity platillo,0,0.01,0
 ;EndIf
 ;If EntityY(platillo)>-0.3 Then
 ;   If KeyDown(208) Then MoveEntity platillo,0,-0.01,0
 ;EndIf
 ;If EntityX(platillo)>-0.4 Then
 ;   If KeyDown(203) Then MoveEntity platillo,-0.01,0,0
 ;EndIf
 ;If EntityX(platillo)<0.4 Then
 ;   If KeyDown(205) Then MoveEntity platillo,0.01,0,0
 ;EndIf

 If KeyHit(32) Then
    crea_balas()
 EndIf
    
End Function 

Type enemigos
   Field tipo[5]
   Field vel#[5]
   Field ex[5]
   Field tv[5]
End Type

Function crea_enemigos()
 enem.enemigos=New enemigos
   For i=1 To 5
       x=Rnd(1,2)*p
       enem\tipo[i]=CreateCube()
       ScaleEntity enem\tipo[i],0.04,0.04,0.04
       PositionEntity enem\tipo[i],x,y,0.5
       EntityType enem\tipo[i],3
       EntityBox enem\tipo[i],-0.02,-0.02,-0.02,0.04,0.04,0.04
       y=y+0.15
       enem\vel[i]=0.01*v
       v=v*-1
       p=p*-1
   Next
End Function 

crea_enemigos()

Function mueve_enemigos()
   For enem.enemigos=Each enemigos
       For i=1 To 5
           MoveEntity enem\tipo[i],enem\vel[i],0,0
       Next

          If EntityX(enem\tipo[1])>0.6 Or EntityCollided(enem\tipo[1],1) Then
             PositionEntity enem\tipo[1],Rnd(-1.3,-0.6),-0.3,0.5
             ResetEntity enem\tipo[1]
          EndIf

          If EntityX(enem\tipo[3])>0.6 Or EntityCollided(enem\tipo[3],1) Then
             PositionEntity enem\tipo[3],Rnd(-1.3,-0.6),0,0.5
             ResetEntity enem\tipo[3]
          EndIf

          If EntityX(enem\tipo[5])>0.6 Or EntityCollided(enem\tipo[5],1) Then
             PositionEntity enem\tipo[5],Rnd(-1.3,-0.6),0.3,0.5
             ResetEntity enem\tipo[5]
          EndIf

          If EntityX(enem\tipo[2])<-0.6 Or EntityCollided(enem\tipo[2],1) Then
             ;HideEntity enem\tipo[2]
             PositionEntity enem\tipo[2],Rnd(0.6,1.3),-0.15,0.5
             ResetEntity enem\tipo[2]
             ;ShowEntity enem\tipo[2]
          EndIf

          If EntityX(enem\tipo[4])<-0.6 Or EntityCollided(enem\tipo[4],1) Then
             ;HideEntity enem\tipo[4]
             PositionEntity enem\tipo[4],Rnd(0.6,1.3),0.15,0.5
             ResetEntity enem\tipo[4]
             ;ShowEntity enem\tipo[4]
          EndIf

   Next
End Function 

Collisions 1,3,3,1
;With this don´t work good :-(. it´s a bug?

;Collisions 1,3,2,1
;With this, work fine! :-) but... why?

While Not KeyHit(1)

movimientos_disparo()
mueve_balas()
mueve_enemigos()

UpdateWorld	
RenderWorld

Text 10,20,"Posición Y: " + EntityY(platillo) 

Flip

Wend
End


the solution is "Collisions 1,3,2,1" but....Why?. I think that then is a bug with entitybox and collisions.

Gracias. :-)