EntityCollided
Blitz3D Forums/Blitz3D Beginners Area/EntityCollided
| ||
| I am sure this is really simple but I have not got it. I have the code Function Block_distroy() For z.map = Each map For x.Bullet = Each Bullet If EntityCollided(x\mesh,z\mesh) DebugLog"Collieded" FreeEntity x\Mesh FreeEntity z\Mesh Delete z Delete x EndIf Next Next End Function The idea of this funcion is that ir detects a collison between the bullet and a boc created by the creat box command. I always thought you used the paramters of enititycolided were the two things which were have collisions checked between, but appears not, I don't know if any one will get what I am going on about but oh well have a look please. Agamer |
| ||
| global mesh1,mesh2 entitytype mesh1,1 entitytype mesh2,2 collisions 1,2,2,1 Function Block_distroy() For z.map = Each map For x.Bullet = Each Bullet If EntityCollided(z\mesh2,2)=x\mesh1 then FreeEntity x\Mesh1 FreeEntity z\Mesh2 Delete z Delete x EndIf Next Next End Function think thats how i did it last time |
| ||
| This is a simple problem that can be solved. Many people make this mistake, including myself. Look at this line: If EntityCollided(x\mesh, z\mesh) If you have collision types assigned to your meshes with "EntityType," you must put the collision TYPE for "z\mesh" instead of the actual mesh.
Const XMESH_TYPE = 1
Const ZMESH_TYPE = 2
For i.map = Each map
EntityType i\mesh, ZMESH_TYPE
Next
For o.Bullet = Each Bullet
EntityType o\mesh, XMESH_TYPE
Next
Then you would replace this line: If EntityCollided(x\mesh, z\mesh) WITH If EntityCollided(x\mesh, ZMESH_TYPE) ;ZMESH_TYPE could also be "2" |
| ||
| Darn it! You beat me to it! |
| ||
| about time i got something right :) well i hope anyways |
| ||
| I still can't seemt o get it. The code for generating the blocks is as follows Function Create_map();Generates the 3d visible map For x=0 To 10 For y=0 To 10 If map(x,y)=2 a.Map = New map a\Mesh =CreateCube () EntityType a\mesh,Col_Scnery PositionEntity a\mesh,x,0,y ScaleEntity a\mesh,0.5,1,0.5 a\Make = Map(x,y) EndIf Next Next End Function and the code once again but modified for delting the blocks as follows. Function Block_distroy() For x.bullet = Each Bullet If EntityCollided(x\mesh,Col_Scnery) DebugLog"Collieded" FreeEntity x\Mesh Delete x EndIf Next End Function and the part to declare the collision types are Const Col_Scnery=2 |
| ||
| post up all your code and i will have a look dont worry about textures or meshes can mocup with spheres |
| ||
ok, I will do in a second, I am sure I am missing something really simple!
;Setup
Graphics3D 800,600,32,2
SeedRnd(MilliSecs())
SetBuffer BackBuffer()
;types
Type Map
Field Mesh
Field Make
End Type
Type Bullet
Field Mesh
Field Age
End Type
;arrays
Dim Map(10,10)
;Variables
Global Quit=False
Global cam
Const Bullet_Life=100
Const Bullet_speed#=0.4
Global Balls=1000
;collions
Const Col_Player=1
Const Col_Scnery=2
Const Col_Blocks=3
Collisions Col_Player,Col_Scnery,2,2
;main Game
;PLayer loading
Global Player=LoadMesh("ball.3ds")
ScaleMesh Player,0.3,0.3,0.3
EntityType Player,Col_player
EntityRadius Player,0.4
;Main camrea
Cam=CreateCamera(Player);this is the main view camrea
TranslateEntity Cam,0,1,-3
PointEntity Cam,PLayer
;Light
light=CreateLight();Creates a light
;INfinte plane
plane=CreatePlane();Makes a simple infinte plane
grass_tex=LoadTexture( "media/metal.png" );loads planes texture
EntityTexture plane,grass_tex;set planes texture
PositionEntity plane,0,-1,0;positions the plane
EntityType Plane,Col_scnery
;EntityAlpha plane,0.9
;mirror=CreateMirror()
;Map camrea
cam2=CreateCamera(cam);Creates the map camrea
TranslateEntity cam2,0,5,0
PointEntity cam2,plane
CameraViewport cam2,0,500,100,100;positions the map
;create the random map
Generate_map()
create_map()
;Physics()
Repeat;Main loop
Movement
Shoot
Update_Bullets
Block_distroy()
UpdateWorld
RenderWorld
GUI
Flip
Finish
Until Quit=True
;end of main loop
;Functions
Function Finish();Detects if the game has finished
If KeyHit(1)
Quit=True
EndIf
End Function
Function Generate_map();Generates the 2d map cordanites
For x=0 To 10
For y=0 To 10
Map(x,y)=Rnd(1,10)
DebugLog map(x,y)
Next
Next
End Function
Function Create_map();Generates the 3d visible map
For x=0 To 10
For y=0 To 10
If map(x,y)=2
a.Map = New map
a\Mesh =CreateCube ()
EntityType a\mesh,Col_Scnery
PositionEntity a\mesh,x,0,y
ScaleEntity a\mesh,0.5,1,0.5
a\Make = Map(x,y)
EndIf
Next
Next
End Function
Function Movement();Controls the players movement
If KeyDown( 205 )=True Then TurnEntity Player,0,-1,0
If KeyDown( 203 )=True Then TurnEntity Player,0,1,0
If KeyDown( 208 )=True Then MoveEntity Player,0,0,-0.05
If KeyDown( 200 )=True Then MoveEntity Player,0,0,0.05
End Function
Function Shoot()
If KeyHit(57)
If Balls > 0
b.Bullet = New bullet
b\Mesh = CreateSphere()
ScaleEntity b\mesh,0.1,0.1,0.1
PositionEntity b\mesh,EntityX(Player),0,EntityZ(player)
RotateEntity b\mesh,0,EntityYaw(Player),0
b\Age=1
Balls=Balls-1
Else
EndIf
EndIf
End Function
Function Update_Bullets()
For all.Bullet = Each Bullet
MoveEntity all\mesh,0,0,Bullet_speed#
all\Age =all\Age + 1
If all\Age >= Bullet_Life
FreeEntity all\Mesh
Delete all
EndIf
Next
End Function
Function GUI()
Color 225,225,225
Text 0,0,Balls
End Function
Function Block_distroy()
For z.Map = Each Map
For x.bullet = Each Bullet
If EntityCollided(x\mesh,Col_Scnery)
DebugLog"Collieded"
FreeEntity x\Mesh
Delete x
EndIf
Next
Next
End Function
|
| ||
| ;Setup Graphics3D 800,600,32,2 SeedRnd(MilliSecs()) SetBuffer BackBuffer() ;types Type Map Field Mesh Field Make End Type Type Bullet Field Mesh Field Age End Type ;arrays Dim Map(10,10) ;Variables Global Quit=False Global cam Const Bullet_Life=100 Const Bullet_speed#=0.4 Global Balls=1000 Global Temp ;collions Const Col_Player=1 Const Col_Scnery=2 Const Col_Blocks=3 Const Col_bullet=4 Collisions Col_Player,Col_Scnery,2,2 Collisions Col_bullet,Col_Scnery,2,2 ;main Game ;PLayer loading Global Player=LoadMesh("ball.3ds") ScaleMesh Player,0.3,0.3,0.3 EntityType Player,Col_player EntityRadius Player,0.4 ;Main camrea Cam=CreateCamera(Player);this is the main view camrea TranslateEntity Cam,0,1,-3 PointEntity Cam,PLayer ;Light light=CreateLight();Creates a light ;INfinte plane plane=CreatePlane();Makes a simple infinte plane grass_tex=LoadTexture( "media/metal.png" );loads planes texture EntityTexture plane,grass_tex;set planes texture PositionEntity plane,0,-1,0;positions the plane EntityType Plane,Col_scnery ;EntityAlpha plane,0.9 ;mirror=CreateMirror() ;Map camrea cam2=CreateCamera(cam);Creates the map camrea TranslateEntity cam2,0,5,0 PointEntity cam2,plane CameraViewport cam2,0,500,100,100;positions the map ;create the random map Generate_map() create_map() ;Physics() Repeat;Main loop Movement Shoot Update_Bullets Block_Checker() UpdateWorld RenderWorld GUI Flip Finish Until Quit=True ;end of main loop ;Functions Function Finish();Detects if the game has finished If KeyHit(1) Quit=True EndIf End Function Function Generate_map();Generates the 2d map cordanites For x=0 To 10 For y=0 To 10 Map(x,y)=Rnd(1,10) DebugLog map(x,y) Next Next End Function Function Create_map();Generates the 3d visible map For x=0 To 10 For y=0 To 10 If map(x,y)=2 a.Map = New map a\Mesh =CreateCube () EntityType a\mesh,Col_Scnery PositionEntity a\mesh,x,0,y ScaleEntity a\mesh,0.5,1,0.5 a\Make = Map(x,y) EndIf Next Next End Function Function Movement();Controls the players movement If KeyDown( 205 )=True Then TurnEntity Player,0,-1,0 If KeyDown( 203 )=True Then TurnEntity Player,0,1,0 If KeyDown( 208 )=True Then MoveEntity Player,0,0,-0.05 If KeyDown( 200 )=True Then MoveEntity Player,0,0,0.05 End Function Function Shoot() If KeyHit(57) If Balls > 0 b.Bullet = New bullet b\Mesh = CreateSphere() EntityType b\mesh,Col_bullet ScaleMesh b\mesh,0.1,0.1,0.1 PositionEntity b\mesh,EntityX(Player),0,EntityZ(player) RotateEntity b\mesh,0,EntityYaw(Player),0 b\Age=1 Balls=Balls-1 Else EndIf EndIf End Function Function Update_Bullets() For all.Bullet = Each Bullet MoveEntity all\mesh,0,0,Bullet_speed# all\Age =all\Age + 1 If all\Age >= Bullet_Life FreeEntity all\Mesh Delete all EndIf Next End Function Function GUI() Color 225,225,225 Text 0,0,Balls End Function Function Block_Checker() temp=0 For a.bullet=Each bullet temp=EntityCollided(a\mesh,Col_Scnery) If temp>0 Then Block_destroy(Temp) If temp>0 Then FreeEntity a\mesh:Delete a:temp=0 Next End Function Function Block_destroy(temp) For b.map=Each map If b\mesh=temp Then FreeEntity b\mesh:Delete b Next End Function try this out got it working is destroying the blocks |
| ||
| Thanks for that, I sort of understand what you have done, so thanks, I can now continue on making my game! |