I am not sure how to enter code on this site, so that it is easily copy and pasted, but if you are even a little interested then
download the latest version of BAM and
copy this into your favorite table under "option explicit in script" and observe the results.
If you play table under debug mode and use manual ball roller with mouse , you will see the contact point assignment as ball rolls over flipper...
Code:
Const BAM_VERSION = 0
AddDebugText BAM_VERSION
' === Dynamic Flipper Settings ===
Sub BAM_Init()
If BAM_VERSION < 233 then Exit Sub
Set RightFlipperExt = xBAM.Flipper("RightFlipper")
Set LeftFlipperExt = xBAM.Flipper("LeftFlipper")
RightFlipperExt.Omega = 43
RightFlipperExt.SetMaterial 0.4, 0.1, 0.05, 0.065
LeftFlipperExt.Omega = 43
LeftFlipperExt.SetMaterial 0.4, 0.1, 0.05, 0.065
End Sub
If BAM_VERSION => 233 then
Dim RightFlipperExt,LeftFlipperExt ' Needed for BAM
Dim omegaCorrection
xBAM.BallSpeedLimit = 3000
End If
Sub OnPreHitFlipperSettings(FlipperExt)
If BAM_VERSION < 233 then Exit Sub
OnPreHitFlipperSettings_bounceControl(FlipperExt)
End Sub
Sub RightFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
OnPreHitFlipperSettings(RightFlipperExt)
omegaCorrection = 43 - (RightFlipperExt.ContactPoint * 14) ' Max omega is 43 and min is 28.2.
If RightFlipperExt.ContactPoint < 0.0 then RightFlipperExt.Omega = 43
If RightFlipperExt.ContactPoint > 1.2 then RightFlipperExt.Omega = 28.2
If (RightFlipperExt.ContactPoint => 0.0) And (RightFlipperExt.ContactPoint =< 1.2) then
RightFlipperExt.Omega = omegaCorrection
End if
AddDebugText "Right Flipper Speed = " &RightFlipperExt.Omega
AddDebugText "RightFlipperExt.ContactPoint= " &RightFlipperExt.ContactPoint
End Sub
Sub LeftFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
OnPreHitFlipperSettings(LeftFlipperExt)
omegaCorrection = 43 - (LeftFlipperExt.ContactPoint * 14)
If LeftFlipperExt.ContactPoint < 0.0 then LeftFlipperExt.Omega = 43
If LeftFlipperExt.ContactPoint > 1.2 then LeftFlipperExt.Omega = 28.2
If (LeftFlipperExt.ContactPoint => 0.0) And (LeftFlipperExt.ContactPoint =< 1.2) then
LeftFlipperExt.Omega = omegaCorrection
End if
AddDebugText "Left Flipper Speed = " &LeftFlipperExt.Omega
AddDebugText "LeftFlipperExt.ContactPoint= " & LeftFlipperExt.ContactPoint
End Sub
'Bounce Control (Note that bounce control over rides flipper elasticity listed above. See lines "RightFlipperExt.Omega ="/"RightFlipperExt.Omega=")
Sub OnPreHitFlipperSettings_bounceControl(FlipperExt)
If BAM_VERSION < 233 then Exit Sub
' Params to tweak
const base_elasticCoef = 0.8 ' very bouncy flipper rubber
const expected_ball_speed_after_hit = 280 ' calc elasticCoef to get desired ball speed after ball hit flipper
const minimum_elasticCoef_to_scale_fast_balls = 0.15 ' we will add this to calculated elastiCoef, so ball after hit will have aditional 5% of speed before hit
const reduction_for_flipper_in_motion = 0.10 ' if flipper is not in starting point, reduce elasticCoef by 10%
const min_elasticCoef = 0.08 ' 2%, ball will almost glue to flipper, this is minimum value
If FlipperExt.Hit Then
Dim elasticCoef
' ball_speed_after_hit = elastic_coef * ball_speed_before_hit
' so, elastic_coef = expected_ball_speed_after_hit / ball_speed_before hit !
elasticCoef = 1.0
If expected_ball_speed_after_hit < xBAM.Ball.Speed Then elasticCoef = expected_ball_speed_after_hit / xBAM.Ball.Speed
' now add little bit to preserv atleast 5% of ball speed before hit (not all balls should end with 240 mm/s)
elasticCoef = elasticCoef + minimum_elasticCoef_to_scale_fast_balls
' make sure, we to not have elasticCoef higher than base value
If elasticCoef > base_elasticCoef Then elasticCoef = base_elasticCoef
' now, reduce elastic coef if flipper is not at StartAngle (1 deg difference or more required)
If FlipperExt.AngleDiff > 1 Then elasticCoef = elasticCoef - reduction_for_flipper_in_motion
' ... finally make sure, that elasticCoef will not be "negative" or to smalll
If elasticCoef < min_elasticCoef Then elasticCoef = min_elasticCoef
FlipperExt.SetMaterial elasticCoef
End If
End Sub
''''''''''''''''''''End of Flipper dynamics'''''''''''''''''''''''''''''''''
Edited by gimli246, 03 December 2018 - 01:04 PM.