Hiding an entity upon colision
Blitz3D Forums/Blitz3D Beginners Area/Hiding an entity upon colision
| ||
I want to hide an item when the player touches it.. for example, Mario gets a coin.. the coin disapears and 1 is added to the coin counter I just want the code as to how to hide an entity when the player mesh colides with it.. |
| ||
You don't just want to hide it, you want to delete it. So use CountCollisions every frame to detect when the player has collided, then use CollisionEntity to get the coin collided against, and finally use FreeEntity to delete the coin. |
| ||
HideEntity coin There you go. |
| ||
thanks jhocking for your sugestion.. and Wolron, I know how the free entity code works, I just dont understand how to apply it through a colision... though jhocking's advice has given me more information to work with, I'm still stubbed as to how to place the code into my current work.. here's my coding so far, take note.. I made the spheres coins, and I'm not really using Mario, but a white sphere named Bob.. this is just so I can attempt to build a decent 3D engine ---------------------------------------------------- Graphics3D 530,340 SetBuffer BackBuffer() Const bob_type=1 Const wld_type=2 Const coin_type=3 ;--Camera------------------------- cam=CreateCamera() CameraClsColor cam,999,999,999 CameraFogMode cam,1 CameraFogRange cam,0,100 CameraFogColor cam,999,999,999 CameraViewport cam,0,0,800,600 MoveEntity cam,0,5,-20 light=CreateLight() ;--------------------------------- ;--Player------------------------- bob=CreateSphere() PositionEntity bob,0,0,0 EntityType bob,bob_type t2=CreateCube() ScaleEntity t2,1,1,1 PositionEntity t2,0,1,0 EntityColor t2,800,43,25 EntityAlpha t2,0 EntityParent cam,t2 ;---------------------------------- ;--Coins (for now)----------------- coin=CreateSphere() ScaleEntity coin,0.5,0.5,0.5 EntityColor coin,100,50,100 EntityType coin,coin_type PositionEntity coin,5,0,0 CopyEntity coin PositionEntity coin,10,0,0 CopyEntity coin PositionEntity coin,15,0,0 CopyEntity coin PositionEntity coin,20,0,0 CopyEntity coin PositionEntity coin,20,0,-5 CopyEntity coin PositionEntity coin,20,0,-10 CopyEntity coin PositionEntity coin,20,0,-15 ;----------------------------------- ;--world---------------------------- wld=CreatePlane() PositionEntity wld,0,-5,0 grs= LoadTexture("grass.bmp") ScaleTexture grs,20,20 EntityTexture wld,grs EntityType wld,wld_type ;------------------------------------ Collisions bob_type,wld_type,2,2 gravity#=.03 jumpvel#=.9 While Not KeyHit(1) If KeyDown(200) MoveEntity bob,0,0,0.5 MoveEntity t2,0,0,0.5 If KeyDown(208) MoveEntity bob,0,0,-0.5 MoveEntity t2,0,0,-0.5 If KeyDown(203) MoveEntity bob,-0.5,0,0 MoveEntity t2,-0.5,0,0 If KeyDown(205) MoveEntity bob,0.5,0,0 MoveEntity t2,0.5,0,0 PointEntity cam,t2 If jumping=0 If KeyDown(54) Then yvel#=jumpvel# jumping=1 EndIf If jumping=1 yvel#=yvel#-gravity# by#=by#+yvel# EndIf If by#<1 Then by#=1 yvel#=0 jumping=0 speed#=speed#*.99 MoveEntity bob,0,yvel#,speed# UpdateWorld RenderWorld Flip Wend End ----------------------------------------------------- can someone explain to me how to place the code into my current code? |
| ||
The code below *should* work, though i haven't had time to test it. |
| ||
hey, sweet! thanks, Diablo **bows** ^_^ If I ever finish a game in 3D, I'll give you credit somehow |
| ||
Best watch with collisions though, as the collision will have a collision response, stopping the player whilst he touches the coin. You can get around that by simply doing a distance check between the player and the coin. Distance checks are super fast and act just like sphere to sphere collisions, without the collision response :o) |
| ||
yes, thats what i'm using with my latest project. though, i think that if you update once you have acted upon the collision you wont have the problem of getting more 'points' than you wanted to give. |