Emitting sound trouble

Blitz3D Forums/Blitz3D Beginners Area/Emitting sound trouble

Chad(Posted 2005) [#1]
Ok, I've been toying with this simple thing now for over a half hour, but can't figure out what I'm doing wrong!

footstep=Load3DSound("C:\Documents and Settings\user\Desktop\moo.wav")
If Sin(90+a1*2)<-.85
If footstep_needed<>1
EmitSound footstep,footstep_needed
footstep_needed=0
EndIf
Else
footstep_needed=1
EndIf

I'm thinking its somewhere in the EmitSound part, the location of the sound is correct (i know lol, just experimenting) but any help is appreciated!

Chad


WolRon(Posted 2005) [#2]
Um, you didn't bother to say what the problem was!

But I think I've figured out your problem. In the EmitSound command, you pass the footstep_needed variable as the entity to emit the sound from.

Either you're confused, or you made a mistake. Replace the footstep_needed variable with one that contains an entities handle.


jfk EO-11110(Posted 2005) [#3]
Yes, footstep_needed has nothing to do with the EmitSound Command! It's only a flipflop varible.

I see you took this snippet from my "headbanger" example. But there' something I don't understand: why did you alter the line

If footstep_needed<>0

to

If footstep_needed<>1

??

This way it's likely that it is never played. Because it works this way: The value of Sin(90+a1*2) will vary between -1.0 and +1.0. At a value of -1.0 the camera reaches the deepest point, representing the point where you will hear the footstep. Since the value -1.0 will not be reached EXACTLY, instead it may be something between -0.85 and -1.0 (due to shoe_size) we need to do the footstep as soon as it's below -0.8499. To prevent playing the sound multiple times we set the variable footstep_needed to zero as soon as we have played it once, and reset it to 1 as soon as the mentioned sin() value is higher than -0.85, to make it ready for the next footstep sound.

BTW if you altered the variable shoe_size and then the example didn't work anymore, you probably need to use a value higher than -0.85, maybe -0.5 or even -0.25 to make sure the step won't be missed. But basicly you need to understand what the code is doing!

Here's the original snippet:
; >>>>>>>>>wobble camera
 If walking=1
  a1#=(a1#+shoe_size) Mod 360
  Else
  ;a1#=a1#*0.8
 EndIf
 PositionEntity camera,Cos(a1#)*head_bang_X#,Sin(90+a1#*2)*head_bang_Y#,0,0

 UpdateWorld
 RenderWorld

 ; >>>>>>>>>control footstep sound
 If Sin(90+a1*2)<-.85 ; camera min distance to ground?
  If  footstep_needed<>0
   Color 255,255,255
   Text 50,50, "Tap!" ; play a footstep once!
   footstep_needed=0 ; disallow further footstep sounds
  EndIf
 Else ; camera out of min distance range,
  footstep_needed=1 ; allow next footstep
 EndIf


I hope I made this clear. And did you create a listener? You need a listener to make 3D Sounds work. But hey, personally I think you don't really need 3D sound for the footsteps of the FPS Camera! because they will come from the same origin, whereever you go. THe foosteps always com from below the camera, so you may use ordinary PlaySound commands instead. You better use 3D Sounds for things that are not fixed with the camera, like example given other Characters footsteps.


Chad(Posted 2005) [#4]
Yeah, thanks guys for the help, I got it working, and yes you cleared it up jfk.

Thanks again!
Chad