Code/Example Tutorial BAM Flipper Bounce Sound (inside the "Dynamic Flippers") for better execution.

Coding and examples for future Pinball and BAM

Paolo

No Bam no Play
Chat Moderator
Site Supporters
Joined
Mar 16, 2013
Messages
1,337
Solutions
3
Reaction score
609
Points
131
Favorite Pinball Machine
Batman(Data East)
Well, thanks to our friend, @NitroNimbus , who reminded me and suggested this.
I honestly talked and shared of this,on Dragon keep Here, but didn't open a suitable thread, so here it is:
Copy this code and paste it under the one of the "Dynamic Flippers" because that's where it belongs.....and don't forget to add sound, to your table,

'--------------------------sound bounce
xBAM.CreateAllExt()

Sub LeftFlipper_preHit()
Flipper_preHit(LeftFlipperExt)
End Sub

Sub RightFlipper_preHit()
Flipper_preHit(RightFlipperExt)
End Sub

Const MinBallSpeed = 100
Const MaxBallSpeed = 1000

Sub Flipper_preHit(FlipperExt)
If Not FlipperExt.Hit Then Exit Sub ' we don't expect hit
If FlipperExt.BallVSpeed < MinBallSpeed Then Exit Sub ' ball moves too slow.. no sound

Dim vol
vol = FlipperExt.BallVSpeed / MaxBallSpeed
If vol > 1 Then vol = 1
PlaySound "fx-rubber", vol*2 ' sound volume

AddDebugText "vol = " & vol & ", CP = " & FlipperExt.ContactPoint
End Sub

View attachment Flipper Bounce Sound.mp4
 

Attachments

  • Flipper Bounce Sound.fpt
    234.5 KB · Views: 74
Hi Wild,
Thanks mate, It works perfectly and really adds to the feel of a real ball hitting the flippers.
Calculating the balls velocity to only register a flipper hit sound when the ball is fast enought to do so is brilliant.
Well done!!, cheers!
 
This is cool! I decided to add it to Twilight Zone. The sound level wasn't really load enough to be heard over the other sounds. I tried adjusting volume in the script but just increasing the sound level in the audio file worked better. The level can be increased by 5 dB and still not clip.

What do you think about moving this topic to "End User Guides"? This seems to be a tutorial.
 
What do you think about moving this topic to "End User Guides"? This seems to be a tutorial.
I think you could add a new window in bam section , for example bam-functions

honestly we are talking about functions of bam, not guide or a tutorial or help....just my thought.
 
Ok,thanks to @GeorgeH and @AnonTet ,who have found and implemented a better way to execute the code, this has also made a significant improvement to the "Dynamic Flippers" code.Here is their work.


NOTE:
the values( in blue) are at your discretion and decision according to your tables.
'Define Game Flags

Dim base_elasticCoef
Dim expected_ball_speed_after_hit
Dim minimum_elasticCoef_to_scale_fast_balls
Dim reduction_for_flipper_in_motion

Sub FuturePinball_BeginPlay()


base_elasticCoef = 0.86 ' very bouncy flipper rubber
expected_ball_speed_after_hit = 300 ' calc elasticCoef to get desired ball speed after ball hit flipper
minimum_elasticCoef_to_scale_fast_balls = 0.11 ' we will add this to calculated elastiCoef, so ball after hit will have aditional 5% of speed before hit
reduction_for_flipper_in_motion = 0.18 ' if flipper is not in starting point, reduce elasticCoef by 20%

Const BAM_VERSION = 0
AddDebugText BAM_VERSION

If BAM_VERSION => 233 then
Dim omegaCorrectionL
Dim omegaCorrectionR
Dim BounceMix
End If

If BAM_VERSION => 233 then
const MinOmega = 32 ' Omega at tip of flipper. Must be < MaxOmega.
const MaxOmegaL = 34 ' Omega at base of left flipper. Must be > MinOmega.
const MaxOmegaR = 34 ' Omega at base of right flipper. Must be > MinOmega.
End If

'''''''''''''''''''''''''''''''''''''''''''''''Left Flipper PreHit Code'''''''''''''''''''''''''''''
Sub LeftFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
Dim ball
Set ball = xBAM.BallCloseTo(0,0)
OnPreHitFlipperSettings(LeftFlipperExt)
omegaCorrectionl = MaxOmegal - (LeftFlipperExt.ContactPoint * ((MaxOmegal - MinOmega)/1.2))
If LeftFlipperExt.ContactPoint < 0.0 then LeftFlipperExt.Omega = MaxOmegal
If LeftFlipperExt.ContactPoint > 1.2 then LeftFlipperExt.Omega = MinOmega
If (LeftFlipperExt.ContactPoint => 0.0) And (LeftFlipperExt.ContactPoint =< 1.2) then
LeftFlipperExt.Omega = omegaCorrectionl
End if
End Sub

''''''''''''''''''''''''''''''''''''''''''''Right Flipper Prehit Code'''''''''''''''''''''''''''''''''''''''
Sub RightFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
Dim ball
Set ball = xBAM.BallCloseTo(0,0)
OnPreHitFlipperSettings(RightFlipperExt)
omegaCorrectionr = MaxOmegar - (RightFlipperExt.ContactPoint * ((MaxOmegar - MinOmega)/1.2))
If RightFlipperExt.ContactPoint < 0.0 then RightFlipperExt.Omega = MaxOmegar
If RightFlipperExt.ContactPoint > 1.2 then RightFlipperExt.Omega = MinOmega
If (RightFlipperExt.ContactPoint => 0.0) And (RightFlipperExt.ContactPoint =< 1.2) then
RightFlipperExt.Omega = omegaCorrectionr
End if
End Sub


Sub OnPreHitFlipperSettings(FlipperExt)
If BAM_VERSION < 254 then Exit Sub
Dim ball
Set ball = xBAM.BallCloseTo(0,0)
If xBAM.Ball.Speed <= 200 then ' 85 is the speed of the ball from a cradled release to the tip of the flipper.
adddebugtext "noBounce"
LeftFlipperExt.SetMaterial 0.62, 0.12, 0.06, 0.075
RightFlipperExt.SetMaterial 0.62, 0.12, 0.06, 0.075
End If
If Not FlipperExt.Hit Then Exit Sub ' we don't expect hit
If FlipperExt.BallVSpeed > 100 Then ' 100 = min ball speed
Dim vol
vol = FlipperExt.BallVSpeed / 1000 ' 1000 = max ball speed
If vol > 1 Then vol = 1
PlaySound "fx-rubber", vol* 2 ' sound volume
AddDebugText "vol = " & vol & ", CP = " & FlipperExt.ContactPoint
End If
If xBAM.Ball.Speed <= 200 then Exit Sub
If FlipperExt.Hit Then
Dim elasticCoef
Dim maxElasticCoef
Dim ballSpeed
ballSpeed = (FlipperExt.BallVSpeed + xBAM.Ball.Speed) * 0.5 ' averge speed of
maxElasticCoef = base_elasticCoef
If FlipperExt.AngleDiff > 1 Then maxElasticCoef = maxElasticCoef - reduction_for_flipper_in_motion
elasticCoef = base_elasticCoef
If ballSpeed > 1 Then elasticCoef = expected_ball_speed_after_hit / ballSpeed
elasticCoef = elasticCoef + minimum_elasticCoef_to_scale_fast_balls
If elasticCoef > maxElasticCoef Then elasticCoef = maxElasticCoef
FlipperExt.SetMaterial elasticCoef
End If
End Sub

various explanations about the "Dynamic Flippers" code

' FLIPPER OMEGA

' You may want to adjust the strength (also called omega) of the flippers when you add dynamic flippers to other tables.
' Only change the values for "MaxOmega" and "MinOmega" These settings override the flipper omega listed in the XML.
' You probably will want to adjust MaxOmega between 40 and 50 and MinOmega between 29 and 33.
' You need to leave the section below "MaxOmega" unchanged and then go on to "BOUNCE CCONTROL" below.
' Gimli likes to be able to change the omega at the base of each flipper so it affects aiming and the option is included here also.

' BOUNCE CONTROL

'Sub OnPreHitFlipperSettings(FlipperExt) ' George
' If BAM_VERSION < 233 then Exit Sub
'If BounceMix = 1 then OnPreHitFlipperSettings_nobounceControl(FlipperExt) ' Bounce Control Turned Off
'If BounceMix = 2 then OnPreHitFlipperSettings_bounceControl(FlipperExt) ' Bounce Control On
'End Sub

' Bounce control is the amount of bounce the ball makes when it hits a stationary flipper. If you want to increase or decrease
' bounce, it can be difficult because there are 4 parameters that you have to adjust. To make it easier, I have provided the
' following list of values that can be entered into the code below. I think the changes from one group of settings to the next result
' in fairly small changes in bounce but you can use the midpoint between two sets of values also. Note that bounce control
' overrides flipper elasticity listed in the XML.

' Suggested values from low bounce on the left to high bounce on the right
' Group: 1 2 3 4 5 6 7 8 9 10 11 12
' base_elasticCoef 0.84 0.86 0.88 0.89 0.91 0.93 0.95 0.97 0.99 1.01 1.03 1.04
' expected_ball_speed_after_hit 280.00 300.00 320.00 340.00 360.00 380.00 400.00 420.00 440.00 460.00 480.00 500.00
' minimum_elasticCoef_to_scale_fast_balls 0.09 0.11 0.13 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.29
' reduction_for_flipper_in_motion 0.19 0.18 0.18 0.17 0.16 0.16 0.15 0.14 0.14 0.13 0.13 0.12



' New Values (where values in the XML for leftYoff equals 0 and rightYoff equals 0)

' Group: 1 2 3 4 5 6 7 8 9 10 11 12
' base_elasticCoef 0.55 0.57 0.59 0.60 0.62 0.64 0.66 0.68 0.70 0.71 0.73 0.75
' expected_ball_speed_after_hit 146.00 170.00 195.00 219.00 243.00 267.00 292.00 316.00 340.00 365.00 389.00 413.00
' minimum_elasticCoef_to_scale_fast_balls 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.09 0.10 0.11
' reduction_for_flipper_in_motion 0.23 0.22 0.21 0.20 0.19 0.19 0.18 0.17 0.16 0.16 0.15 0.14

I think everything is correct, but if I did something wrong please can you intervene.... @GeorgeH @AnonTet
 
In reality, I just moved code that already existed and eliminated some Sub's that I though were unnecessary.

But thanks for mentioning me.

The above looks alright in a quick inspection but if anyone using it has any trouble, fell free to ask for help.
 
Forum activity
Help Users
You can interact with the ChatGPT Bot in any Chat Room and there is a dedicated room. The command is /ai followed by a space and then your ? or inquiry.
ie: /ai What is a EM Pinball Machine?
  • No one is chatting at the moment.
      Chat Bot Mibs Chat Bot Mibs: keefus is our newest member. Welcome!
      Back
      Top