one shot sound
Blitz3D Forums/Blitz3D Beginners Area/one shot sound
| ||
Hi im so glad the forums are back! Ok im using Jv-ode to return collision data which gives me the number of current collisions with a car in my game. now i want to add sound so that when the car hits a wall or other car it plays the hit sound once. no matter what i try the sound either plays once then when i hit another object it doesnt play or anything i hit gets a loop of the hit sound. im not sure how to control the sound so it only plays once per collision. thanks Pete |
| ||
You need to set a state for if the sound is already playing... Some thing like: CarCollisionSndPlaying = False ; Init it false If CarInCollision() If CarCollisionSndPlaying = False ; Play sound CarCollisionSndPlaying = True Else ; Sound already playing - dont play again CarCollisionSndPlaying = False Endif Endif Might also be better to use a Type for your car, the access all the stuff related to the car through that. edit: I think there are commands for SoundPlaying() in Blitz - you could also check those out - can`t remember off the top of my head. |
| ||
there is the stopchannel command and ive done something like what you have above but i can't get it to work right? my last try i did this Global thud=Load3DSound("thud2.mp3") Global thudchannel= PlaySound (thud) PauseChannel thudchannel hits_car1=(dGeom1CountCollisions(CGeom1)) If hits_car1 >0 ResumeChannel (thudchannel) If ChannelPlaying (thudchannel) = False hits_car1 = 0 EndIf EndIf i know that doesnt work but ive tried everything i can think of |
| ||
You are using Load3DSound() - this should then be played using the EmitSound() command (attached to your car object). I`ve changed it to normal LoadSound() here but you coudl change it back to attach it to the car or object being hit etc.Global thud=LoadSound("thud2.mp3") Global thudchannel hits_car1=(dGeom1CountCollisions(CGeom1)) If hits_car1 >0 If ChannelPlaying(thudchannel) = 1 ; Already playing so do nothing Else thudchannel=PlaySound(thud) hits_car1 = 0 EndIf EndIf This should work (cant test atm) but it will only play a collision sound once the existing sample has finished, no matter if you crash again while the sound is playing. To get around this you could write a few functions for playing multiple sounds, so if thudchannel is already playing, then play another sound (scraping or another crash noise). Also look at one of the sound libraries like BASS - I`m sure they will handle stuff like this. Hope that helps |
| ||
thanks .rIKmAN the problem ive got is that even with the car stopped against a wall the collision keeps flicking between 0 and 1 so as soon as the sample finishes it gets triggered again. Your code above would work if i could stop the sample from being retriggered. i get some very odd results with emitsound because im changing the pitch of my engine loop to simulate exceleration. emitsound doesnt seam to respond to channel commands. i did try it, it doesnt seem to make any difference if you use load3dsound when it should be loadsound. Pete |
| ||
You should only play the sound if there is a collision and the vehicle was moving faster than some speed threshold. This should stop it being triggered all the time. |
| ||
good idea stevie G that sounds like the answer, thanks |
| ||
works like a charm. thanks all. for anyone else having trouble heres the code.Global hits_car1 Global thud=LoadSound("thud2.mp3") Global thudchannel hits_car1=(dGeom1CountCollisions(CGeom1)) If hits_car1 >0 If ChannelPlaying(thudchannel) = 1 ; Already playing so do nothing Else If velocity >0.1 thudchannel=PlaySound(thud) hits_car1 = 0 EndIf EndIf EndIf |
| ||
Ah, forgot about this thread :) Glad you got it sorted. |