Hi Olby
searching the word "coll" in Examples\3D i have found several examples dealing with collision,
EntityColide, WorldDebug, FPSFirstPerson, ThirdPerson, TerrainPhysics.
look at
ThirdPerson example the man collide with the boxes and the boxes moves. in the
FPSFirstPerson.pb example the shooter aim at the barrels and when the ball collide with it the barrels fall down and he also can shoot to other balls and it moves and reflects as physics dictate.
they use
RayCollide function and this example can be used to design an exact billiard ball game.
i don't know anything about games. but looking at the examples, here is a ball falling to the ground and it gives a sound when touching the ground.
first you define physics:
EnableWorldPhysics(1)
EntityPhysicBody(#plane,#PB_Entity_StaticBody)
EntityPhysicBody(sphere,#PB_Entity_SphereBody ,2, 5, 0.5)
If EntityCollide(sphere,#plane)
PlaySound(collision)
note also
WorldGravity(-9); change gravity to -2 so the ball fall slower, change it to 1 and the ball will rise up (repulsive gravitation)
you need to download this volleyball sound:
http://www.mediafire.com/?gppre763ec5x9fa
try other objects like box, cylinder etc. look at FPSFirstPerson.pb and how the balls reflects from each other, you can add sounds when they reflect like the example beclow
PS: i have failed to see where to insert PlaySound(collision) in the FPSFirstPerson.pb example so it sounds when a collison happened, the example are too advanced. but if we insert PlaySound(collision) after line 239 ApplyEntityImpulse(Shoot...) it will sound at every left click ie when throwing balls
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
InitSound()
#plane = 8
mainwin = OpenWindow(#PB_Any, 0, 0, 640, 480,"Low Gravity Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(mainwin),0, 0, 640, 480)
Add3DArchive("/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,30))
camera = CreateCamera(#PB_Any,0,0,400,400)
MoveCamera(camera,0, 4, 9,#PB_Absolute)
CameraLookAt(camera,0, 2, 0)
;CameraRenderMode(camera,#PB_Camera_Wireframe)
CreateMaterial(0, LoadTexture(0, "MRAMOR6X6.jpg"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(0))
sphere=CreateSphere(#PB_Any,1,256,256)
;sphere=CreateCube(#PB_Any,2)
sphere=CreateEntity(#PB_Any,MeshID(sphere),#PB_Material_None,3,6,-4)
EnableWorldPhysics(1)
EntityPhysicBody(#plane,#PB_Entity_StaticBody)
EntityPhysicBody(sphere,#PB_Entity_SphereBody ,2, 5, 0.5)
Result.f = WorldGravity(-9.8)
;Debug Result
RotateEntity(#plane,0,0,9)
MoveEntity(#plane,0,0,0)
LoadSound(collision,"volleyball.wav",100)
;PlaySound(collision,#PB_Sound_Loop)
Repeat
If EntityCollide(sphere,#plane)
PlaySound(collision)
EndIf
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(5)=#PB_Event_CloseWindow
FreeSound(collision)
End