Register    Login    Forum    FAQ    PinSimDB.org

Board index » Future Pinball » BAM corner




Post new topic Reply to topic  [ 225 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 23  Next
Author Message
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Wed Dec 12, 2018 2:52 am 
Offline

Joined: Thu Aug 16, 2012 11:12 pm
Posts: 2523
Location: Arkansas, USA
blue wrote:
Thanks Gimli if you do. If you can post any code examples that would help greatly as well. After a long break, I'm starting up again and will be using Dynamic flippers, but I also have a few ideas so may just use my own setup if I feel it's better, or more suitable for Bally type flippers. Some of this stuff I didn't even realize was in there, and wasted quite a bit of time, but if some of this is what I was hoping for, then off to the races I go.


Blue,

Rav provided new bounce code on an earlier posting that I pasted below. The settings in the XML appear to interact with the bounce settings so you may have have set the bounce much higher than you might expect as in the settings in the next set of code below.

George

Code:
Sub OnPreHitFlipperSettings_bounceControl(FlipperExt)
   ' Params to tweak
   const base_elasticCoef                        = 0.8  ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 240  ' calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.05 ' 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.20 ' if flipper is not in starting point, reduce elasticCoef by 20%
 
   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


Code:
   const base_elasticCoef                        = 0.95 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 400  ' calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.20 ' 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.15 ' if flipper is not in starting point, reduce elasticCoef by 20%


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Wed Dec 12, 2018 3:37 am 
Offline

Joined: Tue May 01, 2012 11:13 pm
Posts: 415
Location: Abbotsford
Already figured that one out. Was looking for actual code examples for some of what Gimili actually posted, to save some time for me as I have months of graphics work still to do, and just don't have the time anymore. (Plus lack of internet access now due to kids game addiction) There really should be a wiki or something for this.

_________________
_____________________________________

Latest projects and rants at My Facebook Page
_____________________________________

Latest Project: fpxEngine


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Wed Dec 12, 2018 9:19 am 
Offline

Joined: Mon Jan 27, 2014 12:36 pm
Posts: 2859
Location: Ontario, Canada
blue wrote:
Already figured that one out. Was looking for actual code examples for some of what Gimili actually posted, to save some time for me as I have months of graphics work still to do, and just don't have the time anymore. (Plus lack of internet access now due to kids game addiction) There really should be a wiki or something for this.

https://www.dropbox.com/s/rk8i6h9tdmt0p ... s.rar?dl=0

Here is what I am looking at now,
https://youtu.be/yQ8TfaGDRuU

In the zip file above you will find:
1.Bam Dynamics Continuous Physics Monitor :
If you load in debug Mode F9 then Press "B" on keyboard it will toggle between BAM monitoring parameters ( Ball Speed, Maximum Ball Speed, Vertical Ball Velocity, Horizontal Ball Velocity , and "Ball to Flipper Angle" or Ball Trajectory Vector)
You have to wait 5 seconds between Maximum Ball Speed Readings...

Here is the code and instructions are at top.
Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Start of Monitoring Code''''''''''''''''''''''''''''''''''
'Six Steps to use these functions
'1.Copy Enclosed Code from "Start of Monitoring Code" to "End of Monitoring Code"
'2.Copy  small code segment under Sub FuturePinball_KeyPressed(ByVal KeyCode) . See Below "if keycode = 48 then "
'3.Create a timer in table editor and name it "MaxSpeedTimer"
'4.Add "BamParameter = 1" under Sub FuturePinball_BeginPlay()
'5.Play in debug mode by pressing F9 from table editor screen
'6.Press "B" on keyboard to switch between options

   

Dim BallTrajectory
Dim BamParameter
Dim maxballspeed : maxballspeed = 0
Sub NewtonPhysicsTick()
   BallTrajectory  = Atn2( xBAM.Ball.Velocity.X, xBAM.Ball.Velocity.y )
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If BamParameter = 1 then AddDebugText "ball.Speed: " & ball.Speed
   If BamParameter = 3 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamParameter = 4 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamParameter = 5 then AddDebugText "xBAM.Ball.Velocity.X: " & xBAM.Ball.Velocity.X
   If BamParameter = 6 then AddDebugText "xBAM.Ball.Position.X: " & xBAM.Ball.Position.X
   If BamParameter = 7 then AddDebugText "BallTrajectory: " & BallTrajectory
   If BamParameter = 8 then
      AddDebugText "ball.Speed: " & ball.Speed
      AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
      AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
      AddDebugText "xBAM.Ball.Velocity.X: " & xBAM.Ball.Velocity.X
      AddDebugText "xBAM.Ball.Position.X: " & xBAM.Ball.Position.X
   End if
   If ball.Exist Then
      If ball.Speed > maxballspeed Then 
         maxballspeed = ball.Speed
         If BamParameter = 2 then AddDebugText "max speed is: " & maxballspeed:MaxSpeedTimer.Set True, 5000 'Maximum ball Speed will be reset every 5 seconds
         
     End If
   End If
End Sub

' Convert X, Y velocities to ball trajectory angle
Const RadToDeg = 57.295779513082320876798154814105 
Function Atn2(x, y)
   If x > 0 Then
      Atn2 = Atn(y / x) * RadToDeg
   ElseIf x < 0 Then
      Atn2 = 180 - RadToDeg * Atn(y / -x)
   ElseIf y > 0 Then
      Atn2 = 90
   Else
      Atn2 = -90
   End If
   Atn2 = Atn2+90
End Function


Sub MaxSpeedTimer_Expired()  'you must add a timer in table editor called "MaxSpeedTimer"
   MaxSpeedTimer.Set False
   maxballspeed = 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''End of Monitoring Code'''''''''''''''''''''''''''''''''''''''''''''''


2. BAM Dynamics Flipper Extensions ( Flipper contact parameters for Prehit Code)
If you load in debug Mode F9 then Press "B" on keyboard it will toggle between BAM monitoring parameters ( Contact Point, Ball Speed, Vertical Ball Velocity, Horizontal Ball Velocity , and "Ball to Flipper Angle" or Flipper Angle), FlippetMass, FlipperOmega, ball position x and y, I forgot to add Flipper elastcoef, static and kinetic friction
https://youtu.be/s-HImLXy6Rw


Here is the code, the directions are the same:


Code:
'''''''''''''''''''''''''''''''''''Dynamic Flipper Mod'''''''''''''''''''''''''''''
       Dim RightFlipperExt
   Set RightFlipperExt       = xBAM.Flipper("RightFlipper")
   Dim LeftFlipperExt
   Set LeftFlipperExt       = xBAM.Flipper("LeftFlipper")

Dim prehitidx
Dim BamParameter
prehitidx = 0
Sub RightFlipper_prehit()
   ball_to_flipper_angle =  Atn2( RightFlipperExt.BallHSpeed, RightFlipperExt.BallVSpeed )
   'If xBAM.Ball.Speed < 300 then
   'RightFlipperExt.Mass      =      20000
   'RightFlipperExt.Omega     =        40
   'End if
   'If xBAM.Ball.Speed > 300 then
   'RightFlipperExt.Mass      =      20000
   'RightFlipperExt.Omega     =       25
   'End if
   prehitidx = prehitidx + 1
   AddDebugText "on pre hit: " & prehitidx
   If BamParameter = 1 then AddDebugText "RightFlipperExt.ContactPoint: " & RightFlipperExt.ContactPoint
   If BamParameter = 2 then AddDebugText "RightFlipperExt.Mass : " & RightFlipperExt.Mass
   If BamParameter = 3 then AddDebugText "RightFlipperExt.Omega : " & RightFlipperExt.Omega
   If BamParameter = 4 then AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   If BamParameter = 5 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamParameter = 6 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamParameter = 7 then AddDebugText "RightFlipperExt.Angle: " & RightFlipperExt.Angle
   If BamParameter = 8 then AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle

   If BamParameter = 9 then
   AddDebugText "RightFlipperExt.ContactPoint: " & RightFlipperExt.ContactPoint
   AddDebugText "RightFlipperExt.Mass : " & RightFlipperExt.Mass
   AddDebugText "RightFlipperExt.Omega : " & RightFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "RightFlipperExt.Angle: " & RightFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   End if
End Sub

Sub LeftFlipper_prehit()
   ball_to_flipper_angle = - Atn2( LeftFlipperExt.BallHSpeed, LeftFlipperExt.BallVSpeed )
   'If xBAM.Ball.Speed < 300then
   'LeftFlipperExt.Mass      =      20000
   'LeftFlipperExt.Omega     =        40
   'End if
   'If xBAM.Ball.Speed > 300 then
   'LeftFlipperExt.Mass      =      20000
   'LeftFlipperExt.Omega     =        25
   'End if
   prehitidx = prehitidx + 1
   AddDebugText "on pre hit: " & prehitidx
   
   If BamParameter = 1 then AddDebugText "LeftFlipperExt.ContactPoint: " & LeftFlipperExt.ContactPoint
   If BamParameter = 2 then AddDebugText "LeftFlipperExt.Mass : " & LeftFlipperExt.Mass
   If BamParameter = 3 then AddDebugText "LeftFlipperExt.Omega : " & LeftFlipperExt.Omega
   If BamParameter = 4 then AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   If BamParameter = 5 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamParameter = 6 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamParameter = 7 then AddDebugText "LeftFlipperExt.Angle: " & LeftFlipperExt.Angle
   If BamParameter = 8 then AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle

   If BamParameter = 9 then
   AddDebugText "LeftFlipperExt.ContactPoint: " & LeftFlipperExt.ContactPoint
   AddDebugText "LeftFlipperExt.Mass : " & LeftFlipperExt.Mass
   AddDebugText "LeftFlipperExt.Omega : " & LeftFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "LeftFlipperExt.Angle: " & LeftFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   End if
End Sub

Const RadToDeg = 57.295779513082320876798154814105

' Convert X, Y to angle.
' Need example? See Atn2Example.
Function Atn2(x, y)
   If x > 0 Then
      Atn2 = Atn(y / x) * RadToDeg
   ElseIf x < 0 Then
      Atn2 = 180 - RadToDeg * Atn(y / -x)
   ElseIf y > 0 Then
      Atn2 = 90
   Else
      Atn2 = -90
   End If
   Atn2 = Atn2+90
End Function


Dim ball_to_flipper_angle

''''''''''''''''''''''''''''''''''''''''''''''''''''''''


So in the prehit code , we simply have things that we can temporarily set (flipper omega, mass, elastcoef, static and kinetic friction) relative to the state of any combination of the parameters mentionned above...

My current goal is:
1. Great aiming
2. Realistic bounce
3. Ball never looks like it is skidding

Observations:
1.I find flipper aiming from a cradled position with original or no bounce control best...
2. I find bounce is improved with new bounce control settings
3. Decreasing ball damping in XML gets rid of visual skidding but adds unmanageable spin...

Proposed solutions
1. Turn bounce control off when ball is cradled
Or when rolling down flipper slowly
2. Somehow make ball appear to roll when skidding (damping of side spin only would help)

Maybe lowering friction will negate crazy spin physics.

I just had a crazy idea (what else is new...)


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Wed Dec 12, 2018 2:30 pm 
Offline

Joined: Thu Aug 16, 2012 11:12 pm
Posts: 2523
Location: Arkansas, USA
I think turning bounce control off when the ball is cradled sounds better than trying to figure out how to change damping. I'm not sure how you will detect when ball is cradled. About all I can think of is to identify the point on the flipper that is hit by the cradled ball and is held there for a few milliseconds. The ball's point of contact on the flipper will probably be different for different flipper angles and different tables. I suppose some sort of test could be done to identify the point of contact.

George


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Wed Dec 12, 2018 4:53 pm 
Offline

Joined: Mon Jan 27, 2014 12:36 pm
Posts: 2859
Location: Ontario, Canada
GeorgeH wrote:
I think turning bounce control off when the ball is cradled sounds better than trying to figure out how to change damping. I'm not sure how you will detect when ball is cradled. About all I can think of is to identify the point on the flipper that is hit by the cradled ball and is held there for a few milliseconds. The ball's point of contact on the flipper will probably be different for different flipper angles and different tables. I suppose some sort of test could be done to identify the point of contact.

George

When the ball is cradled ball.speed =0 and we have the ball to flipper angles when ball rolls down flippers so it is easy...

I can attach a ball toy to the real ball and make it spin based on velocity to create an illusion that the ball doesn't skid....that way we can set damping as wish but ball will always appear to spin when velocity is greater than 0

Bam already does this but I haven't checked "skidding"

You should see the cool flashing ball Drakko created , I may leak a video of it...


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Thu Dec 13, 2018 1:40 am 
Offline

Joined: Tue May 01, 2012 11:13 pm
Posts: 415
Location: Abbotsford
@ George: Probably the reason is Rav supplied 3 sets of physics, and there is a conflict. If you have this code (usually in BAM_Init) Then remark it out and you will find Bounce control settings will be far more closer to normal
Code:
[code]   '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[/code]


@ Gimli Thank you, wish we had done this a while back. Next time I have a few hours, will look at this, fold in my stuff from my work table and have a master fpt for adjusting flipper dynamics. Since my table is a Bally type, and not a williams type, I will see if I can tune it to Bally and then fire off a copy to a couple Bally experts, as the physics are very different with Bally compared to the wpc type flipper settings you have.

EDIT. Gimli, forgot your xml. It's okay, i was going to rebuild it all anyway for my Physics work fpt, once I have a few hours spare. Have my own reporting system as well. My flipper dynamics are a bit different, and only just starting them. Be interesting what I come up with.

_________________
_____________________________________

Latest projects and rants at My Facebook Page
_____________________________________

Latest Project: fpxEngine


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Thu Dec 13, 2018 7:26 am 
Offline

Joined: Tue May 01, 2012 11:13 pm
Posts: 415
Location: Abbotsford
Okay first question

You can tell if a flipper is hit (If FlipperExt.Hit Then) but how do you find out scriptwise if the Flipper is UnHit? IF Then Else statements don't work, and there seems to be no code for the "Flag" Rav mentioned. Here's the code, it just ignores the Unhit portion completely, no matter how I do it.

Code:
      If RightFlipperExt.Hit Then         
         HudRFO.Text= "RF Omega -  " & (RightFlipperExt.Omega)
         HudRFH.Text= "RFHSpeed -  " & (RightFlipperExt.BallHSpeed)
         HudRFV.Text= "RFVSpeed -  " & (RightFlipperExt.BallVSpeed)
         HudRFC.Text= "RF Contact -  " & (RightFlipperExt.ContactPoint)
         HudRFA.Text= "RF Angle -  " & (RightFlipperExt.Angle)
      End if
      If RightFlipperExt.Hit = FALSE  Then
         AddDebugText "RFlipper UnHit"
         AddDebugText "RFlipper Time Hit - " & (zCountRightFlipper) & " (ms)"
         zCountRightFlipper=0
      End If


This code does work but sort of... ( i'm too tired now to fix it)
Code:
' TIMER USED TO SHOW AND UPDATE PHYSICS IN REAL TIME
Sub TimerRFDebug_Expired()
      If RightFlipperExt.Hit Then zCountRightFlipper=zCountRightFlipper+1:dRightFlipperHit():End If
      If LeftFlipperExt.Hit Then
         HudLFO.Text= "LF Omega -  " & (LeftFlipperExt.Omega)
         HudLFH.Text= "LFHSpeed -  " & (LeftFlipperExt.BallHSpeed)
         HudLFV.Text= "LFVSpeed -  " & (LeftFlipperExt.BallVSpeed)
         HudLFC.Text= "LF Contact -  " & (LeftFlipperExt.ContactPoint)
         HudLFA.Text= "LF Angle -  " & (LeftFlipperExt.Angle)
      End If
         HudBSpeed.Text= "Ball Speed - " & (xBAM.Ball.Speed)
         HudDmdBPos.Text= "Ball x - " & (xBAM.Ball.Position.X) & " " & "y - " & (xBAM.Ball.Position.y)
         HudDmdBVel.Text= "Vel x -  " & (xBAM.Ball.Velocity.X) & " " & "y - " & (xBAM.Ball.Velocity.Y)
   TimerRFDebug.Set True, 1
End Sub

Sub dRightFlipperHit()
      If RightFlipperExt.Hit Then         
         HudRFO.Text= "RF Omega -  " & (RightFlipperExt.Omega)
         HudRFH.Text= "RFHSpeed -  " & (RightFlipperExt.BallHSpeed)
         HudRFV.Text= "RFVSpeed -  " & (RightFlipperExt.BallVSpeed)
         HudRFC.Text= "RF Contact -  " & (RightFlipperExt.ContactPoint)
         HudRFA.Text= "RF Angle -  " & (RightFlipperExt.Angle)
      End If
      IF zCountRightFlipper=1 Then
         AddDebugText "RFlipper Hit"
         xRightFlipperExtOmega=(RightFlipperExt.Omega)
      END IF
End Sub

' PART OF KEY DOWN SUB. This executes when the flipper button is released
      case "LEFTFLIPPER-RELEASED"
         LeftFlipper.SolenoidOff
         PlaySound "FlipperDown"
         If zCountRightFlipper>=1 Then
            AddDebugText "RFlipper UnHit"
            AddDebugText "RFlipper Time Hit - " & (zCountRightFlipper) & " (ms)"
            zCountRightFlipper=0
            ' Add Ending code for when ball leaves flipper
         End If

_________________
_____________________________________

Latest projects and rants at My Facebook Page
_____________________________________

Latest Project: fpxEngine


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Thu Dec 13, 2018 2:13 pm 
Offline

Joined: Mon Jan 27, 2014 12:36 pm
Posts: 2859
Location: Ontario, Canada
blue I am not sure about
Code:
RightFlipperExt.Hit = FALSE

Haven't tested the "hit " function yet sorry

but here is a dynamic flipper code that seems to work quite well on the
Indy table that I am modding.


You are right about removing the Set material code from Sub BAM_init.

The following code has 3 "bouncemix" settings available but is only using two of them.
1. No Bounce control applied -resets to parameters as set in xml file
2.Original Ravarcade bounce control
3.Ravarcade Vertical average

I have it set to 1.No Bounce Control at low speeds (for example after a cradled ball)
as I think flipper aiming is best.
and set to 2.Rav Original Bounce control at speeds > 200

Here is the whole dynamic code template with
1.embedded xml
2.Dynamic flippers
3.Bounce control
4.Debug template with for all physics settings
5. Press "B" for monitoring and "V" for flipper contacting settings
you can toggle between settings and view them concurrently or separately
as the tenth keypress voids debug screen...

Code:
' ============================== CUT HERE START ===============
' This part is added to prevent script errors if BAM is not here
' Put it below "Option Explicit" and remove "Option Explicit"
' If you don't remove it, you will get errors in script

' HOW TO COPY DYNAMIC FLIPPERS TO YOUR TABLE
' __________________________________________
'
' Some of the guys have requested a way for a novice to add dynamic flippers to other tables. 
' I have adjusted the flipper settings to work with the XML file that has been added below.  I recommend
' copying the XML along with the flipper settings. I actually tweak the settings very minimally in my custom
' physics tables so the settings should work for you.  Just copy all the lines of this script from
' "HOW TO COPY DYNAMIC FLIPPERS TO YOUR TABLE" down to "End of Dynamic Flipper Settings".  Then paste
' into your table BELOW THE LINE that says "Option Explicit" in the script.  I recommend changing the
' strength of the main slingshots located just above the flippers in the table editor to their minimum
' setting for the table to play better. .Some additional guidance is provided in the "FLIPPER OMEGA" and
' "BOUNCE CCONTROL" sections below.  You may need to adjust the "MinOmega" in the "FLIPPER OMEGA" section 
' below.  You should try the rest of the content to see it it works for you. 

'=============================== PHYSICS XML ===========================
'<?xml version="1.0" encoding="utf-8"?>
'<document>
'  <!—Custom Physics for Medieval Madness -->
'  <physics fps="296" threaded="1"></physics>
'  <ball newtonDamping="0" mass="72" gravity="5300" damping="1.25"></ball>
'  <flipper releaseOmega="18" rotationSpeedChart="{0.0,100.0}[0.0,100.0]" newtonDamping="1" mass="20150" omega="43" moeMethod="0"
'           leftXoff="0" leftYoff="1500" leftZoff="0"
'           rightXoff="0" rightYoff="1500" rightZoff="0"></flipper>
'  <bumper impulse="90.0" impulseRandomness="0" vectorRandomness="6"></bumper>
'  <autoplunger mass="20000.0" force="60000.0"></autoplunger>
'  <diverter mass="10000.0" omega="33.0"></diverter>
'  <gate mass="5.0" gravity="2500.0" damping="0.25"></gate>
'  <kicker impulse="1000.0" vukImpulse="1400.0" impulseRandomness="2" vectorRandomness="1"></kicker>
'  <plunger mass="20000.0" force="30000.0"></plunger>
'  <slingshot impulse="500.0" impulseRandomness="15" vectorRandomness="3"></slingshot>
'  <spindisk mass="10000.0" angularDamp="0.33" linearDamp="0.25"></spindisk>
'  <spinner mass="60.0" gravity="100.0" angularDamp="0.25" angularAccel="5.25"
'           spinDampLoose="0.55" spinBackLoose="1.70"
'           spinDampNorm="0.75" spinBackNorm="1.80"
'           spinDampTight="0.95" spinBackTight="1.90"></spinner>
'  <emkicker mass="10000.0" omega="80.0"></emkicker>
'  <varitarget mass="500.0" damping="0.9" tension="3.0" return="15.0"></varitarget>
'  <magnet impulse="10.0" impulseRandomness="2"></magnet>
'  <nudge impulse="120.0" impulseRandomness="25.0" warningLevel="260" leftAngle="60" upAngle="0" rightAngle="320"
'         vectorRandomness="5" visualDistance="1" waitPeriod="300" maxBallVelocity="500.0"></nudge>
'  <defaultMat softnessCoef="0.02" elasticCoef="0.1" staticFriction="0.02" kineticFriction="0.02"></defaultMat>
'  <playfieldMat softnessCoef="0.03" elasticCoef="0.1" staticFriction="0.025" kineticFriction="0.015"></playfieldMat>
'  <metalMat softnessCoef="0.01" elasticCoef="0.1" staticFriction="0.01" kineticFriction="0.01"></metalMat>
'  <woodMat softnessCoef="0.03" elasticCoef="0.15" staticFriction="0.03" kineticFriction="0.02"></woodMat>
'  <plasticMat softnessCoef="0.02" elasticCoef="0.2" staticFriction="0.02" kineticFriction="0.01"></plasticMat>
'  <rubberHardMat softnessCoef="0.08" elasticCoef="0.42" staticFriction="0.04" kineticFriction="0.055"></rubberHardMat>
'  <rubberIntMat softnessCoef="0.1" elasticCoef="0.52" staticFriction="0.05" kineticFriction="0.065"></rubberIntMat>
'  <rubberSoftMat softnessCoef="0.12" elasticCoef="0.62" staticFriction="0.06" kineticFriction="0.075"></rubberSoftMat>
'  <gateMat softnessCoef="0.05" elasticCoef="0.65" staticFriction="0" kineticFriction="0"></gateMat>
'  <kickerMat softnessCoef="0.01" elasticCoef="0.05" staticFriction="0.8" kineticFriction="0.8"></kickerMat>
'  <rampMat softnessCoef="0.01" elasticCoef="0.01" staticFriction="0.01" kineticFriction="0.01"></rampMat>
'  <plungerMat softnessCoef="0.04" elasticCoef="0.55" staticFriction="0.02" kineticFriction="0.02"></plungerMat>
'  <spindiskMat softnessCoef="0.05" elasticCoef="0.5" staticFriction="1.5" kineticFriction="2"></spindiskMat>
'</document>
'=============================== PHYSICS XML ===========================

' === Dynamic Flipper Settings ===


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Start of Monitoring Code''''''''''''''''''''''''''''''''''
'Three Steps to use these functions
'1.Copy Enclosed Code from "Start of Monitoring Code" to "End of Monitoring Code"
'2.Copy  small code segment under Sub FuturePinball_KeyPressed(ByVal KeyCode) .
   ' If KeyCode = 48 Then  'B on keyboard is cheat key
      'BamMonitor = BamMonitor + 1
      'If BamMonitor = 11 then BamMonitor = 1
      'maxballspeed = 0
   'End If

   'If KeyCode = 47 Then  'B on keyboard is cheat key
      'BamParameter = BamParameter + 1
      'If BamParameter = 11 then BamParameter = 1
   'End If

'4. Under Sub FuturePinball_BeginPlay() add the following: BamMonitor = 0:BamParameter = 0
'5.Create a timer in table editor and name it "MaxSpeedTimer"
'6.Play in debug mode by pressing F9 from table editor screen
'7.Press "B" on keyboard to switch between monitoring options and "V"for prehit flipper contact parameters

Dim BallTrajectory
Dim BamMonitor
Dim BamParameter
Dim maxballspeed : maxballspeed = 0
Sub NewtonPhysicsTick()
   BallTrajectory  = Atn2( xBAM.Ball.Velocity.X, xBAM.Ball.Velocity.y )
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If BamMonitor = 1 then AddDebugText "ball.Speed: " & ball.Speed
   If BamMonitor = 3 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamMonitor = 4 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamMonitor = 5 then AddDebugText "xBAM.Ball.Velocity.X: " & xBAM.Ball.Velocity.X
   If BamMonitor = 6 then AddDebugText "xBAM.Ball.Position.X: " & xBAM.Ball.Position.X
   If BamMonitor = 7 then AddDebugText "BallTrajectory: " & BallTrajectory
   If BamMonitor = 8 then AddDebugText "BounceMix: " & BounceMix
   If BamMonitor = 9 then
      AddDebugText "ball.Speed: " & ball.Speed
      AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
      AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
      AddDebugText "xBAM.Ball.Velocity.X: " & xBAM.Ball.Velocity.X
      AddDebugText "xBAM.Ball.Position.X: " & xBAM.Ball.Position.X
      AddDebugText "BounceMix: " & BounceMix
   End if
   If BamParameter = 10 then AddDebugText ""
   If ball.Exist Then
      If ball.Speed > maxballspeed Then 
         maxballspeed = ball.Speed
         If BamParameter = 2 then AddDebugText "max speed is: " & maxballspeed:MaxSpeedTimer.Set True, 5000 'Maximum ball Speed will be reset every 5 seconds
         
     End If
   End If
End Sub

' Convert X, Y velocities to ball trajectory angle
Const RadToDeg = 57.295779513082320876798154814105 
Function Atn2(x, y)
   If x > 0 Then
      Atn2 = Atn(y / x) * RadToDeg
   ElseIf x < 0 Then
      Atn2 = 180 - RadToDeg * Atn(y / -x)
   ElseIf y > 0 Then
      Atn2 = 90
   Else
      Atn2 = -90
   End If
   Atn2 = Atn2+90
End Function


Sub MaxSpeedTimer_Expired()  'you must add a timer in table editor called "MaxSpeedTimer"
   MaxSpeedTimer.Set False
   maxballspeed = 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''End of Monitoring Code''''''''''''''''''''''''''''''''''''''''''''''' 

Const BAM_VERSION = 0
AddDebugText BAM_VERSION

If BAM_VERSION > 179 Then xBAM.FixScore

If BAM_VERSION => 233 then
Dim RightFlipperExt,LeftFlipperExt            ' Needed for BAM
 Dim omegaCorrection
xBAM.BallSpeedLimit = 2500
End If   
   

Sub BAM_Init()
   If BAM_VERSION < 233 then Exit Sub
   Set RightFlipperExt      = xBAM.Flipper("RightFlipper")
   Set LeftFlipperExt       = xBAM.Flipper("LeftFlipper")
   RightFlipperExt.Omega    =         47
   LeftFlipperExt.Omega     =         43
End Sub


' FLIPPER OMEGA

' You may want to adjust the strength (also called omega) of the flippers when you add dynamic flipper 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 "MinOmega" unchanged and then go on to "BOUNCE CCONTROL" below.

If BAM_VERSION => 233 then
   const MaxOmegaL  = 43  ' Omega at base of flipper.  Must be > MinOmega. Default = 45
   const MinOmegaL  = 32  ' Omega at tip of flipper. Must be < MaxOmega. Default = 31.5
    const MaxOmegaR  = 47  ' Omega at base of flipper.  Must be > MinOmega. Default = 45
   const MinOmegaR  = 32  ' Omega at tip of flipper. Must be < MaxOmega. Default = 31.5
End If

Dim BounceMix
Dim ball_to_flipper_angle
''''''''''''''''''''''''''''''''''''''''''''Right Flipper Prehit Code'''''''''''''''''''''''''''''''''''''''

Sub RightFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
   ball_to_flipper_angle =  Atn2( RightFlipperExt.BallHSpeed, RightFlipperExt.BallVSpeed )
   
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If xBAM.Ball.Speed <= 200 then BounceMix = 1 'Ball Speed Measures 150 rolling down left fliper from cradled ball so this should capture it
   If xBAM.Ball.Speed > 200  then  BounceMix = 2
      

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
If BamParameter = 1 then AddDebugText "RightFlipperExt.ContactPoint: " & RightFlipperExt.ContactPoint
   If BamParameter = 2 then AddDebugText "RightFlipperExt.Mass : " & RightFlipperExt.Mass
   If BamParameter = 3 then AddDebugText "RightFlipperExt.Omega : " & RightFlipperExt.Omega
   If BamParameter = 4 then AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   If BamParameter = 5 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamParameter = 6 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamParameter = 7 then AddDebugText "RightFlipperExt.Angle: " & RightFlipperExt.Angle
   If BamParameter = 8 then AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle

   If BamParameter = 9 then
   AddDebugText "RightFlipperExt.ContactPoint: " & RightFlipperExt.ContactPoint
   AddDebugText "RightFlipperExt.Mass : " & RightFlipperExt.Mass
   AddDebugText "RightFlipperExt.Omega : " & RightFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "RightFlipperExt.Angle: " & RightFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   End if
   If BamParameter = 10 then AddDebugText ""
End Sub


'''''''''''''''''''''''''''''''''''''''''''''''Left Flipper PreHit Code'''''''''''''''''''''''''''''
 
Sub LeftFlipper_prehit()
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If ball.Speed <= 200 then BounceMix = 1 'Ball Speed Measures 150 rolling down left fliper from cradled ball so this should capture it
   If xBAM.Ball.Speed <= 200 then BounceMix = 1 'Ball Speed Measures 150 rolling down left fliper from cradled ball so this should capture it
   If xBAM.Ball.Speed > 200  then  BounceMIx = 2
If BAM_VERSION < 233 then Exit Sub
   ball_to_flipper_angle =  Atn2( LeftFlipperExt.BallHSpeed, LeftFlipperExt.BallVSpeed )
   
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
If BamParameter = 1 then AddDebugText "LeftFlipperExt.ContactPoint: " & LeftFlipperExt.ContactPoint
   If BamParameter = 2 then AddDebugText "LeftFlipperExt.Mass : " & LeftFlipperExt.Mass
   If BamParameter = 3 then AddDebugText "LeftFlipperExt.Omega : " & LeftFlipperExt.Omega
   If BamParameter = 4 then AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   If BamParameter = 5 then AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   If BamParameter = 6 then AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   If BamParameter = 7 then AddDebugText "LeftFlipperExt.Angle: " & LeftFlipperExt.Angle
   If BamParameter = 8 then AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle

   If BamParameter = 9 then
   AddDebugText "LeftFlipperExt.ContactPoint: " & LeftFlipperExt.ContactPoint
   AddDebugText "LeftFlipperExt.Mass : " & LeftFlipperExt.Mass
   AddDebugText "LeftFlipperExt.Omega : " & LeftFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "LeftFlipperExt.Angle: " & LeftFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   End if
   If BamParameter = 10 then AddDebugText ""
End Sub


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' BOUNCE CCONTROL


' Bounce control is the amount of bounce the ball makes when it hits the flippers.  You may want to leave these settings unchanged. 
' I would suggest small changes here of "base_elasticCoef" and "expected_ball_speed_after_hit".

'(Note that bounce control over rides flipper elasticity listed in the XML. See lines "RightFlipperExt.Omega ="/"RightFlipperExt.Omega=")


Sub OnPreHitFlipperSettings(FlipperExt)
   If BAM_VERSION < 233 then Exit Sub
 'Exit Sub 'turn if off no bounce control
If BounceMix = 1 then OnPreHitFlipperSettings_nobounceControl(FlipperExt)
If BounceMix = 3 then OnPreHitFlipperSettings_bounceControl_verticalAverge(FlipperExt)
If BounceMix = 2 then OnPreHitFlipperSettings_bounceControl(FlipperExt) 'Original Rav Bounce
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''Original Ravarcade Bounce Control'''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnPreHitFlipperSettings_bounceControl(FlipperExt)
   
   If BAM_VERSION < 233 then Exit Sub
   ' Params to tweak
   const base_elasticCoef                        = 0.90 'george .95 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 370 '400 calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.20 ' 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.15 ' if flipper is not in starting point, reduce elasticCoef by 20%
 
   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
''''''''''''''''''''''''''''''''''''''''''''''Ravarcade Bounce Control Based on average vertical velocity'''''''''''''''''''

Sub OnPreHitFlipperSettings_bounceControl_verticalAverge(FlipperExt)
   ' Params to tweak
   const base_elasticCoef                        = 0.95 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 400  ' calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.20 ' 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.15 ' if flipper is not in starting point, reduce elasticCoef by 20%
   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
''''''''''''''''''''''''''''''''''''''''''''No Bounce Control Reset Values from xml'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnPreHitFlipperSettings_nobounceControl(FlipperExt)

   RightFlipperExt.SetMaterial       0.62,        0.12,       0.06,      0.075
   LeftFlipperExt.SetMaterial       0.62,        0.12,       0.06,      0.075
   
End Sub


 ' ============================== CUT HERE END =================


The code has instructions for adding a timer for MaxSpeed reset
and where to place the if keycode comments for pressing "B" and "V" to make the debug
physics monitoring work...

'1.Copy Enclosed Code from "Start of Monitoring Code" to "End of Monitoring Code"
'2.Copy small code segment under Sub FuturePinball_KeyPressed(ByVal KeyCode) .
' If KeyCode = 48 Then 'B on keyboard is cheat key
'BamMonitor = BamMonitor + 1
'If BamMonitor = 11 then BamMonitor = 1
'maxballspeed = 0
'End If

'If KeyCode = 47 Then 'B on keyboard is cheat key
'BamParameter = BamParameter + 1
'If BamParameter = 11 then BamParameter = 1
'End If

'4. Under Sub FuturePinball_BeginPlay() add the following: BamMonitor = 0:BamParameter = 0
'5.Create a timer in table editor and name it "MaxSpeedTimer"
'6.Play in debug mode by pressing F9 from table editor screen
'7.Press "B" on keyboard to switch between monitoring options and "V"for prehit flipper contact parameters


Last edited by Gimli on Thu Dec 13, 2018 8:51 pm, edited 1 time in total.

Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Thu Dec 13, 2018 7:45 pm 
Offline

Joined: Tue May 01, 2012 11:13 pm
Posts: 415
Location: Abbotsford
Thank you. Will have a look at this when I have the time. I guess I am writing my own physics test table so if it's good enough for others to use then that's cool.

As you can see, I have my own timer and display code, and the basic idea is to have the physics statements written to the debug text file when a user presses a button. There may be a lot more than just that, a long time ago I had a basic menu system that allowed the user to adjust various settings while in game(including basic scoring). BAM has that as well, but I find it a little overwhelming and harder to use, as I keep forgetting where everything is in that menu.

Unfortunately, It has to be DMD based. I keep running into all those forced restrictions that Black left in there, so even simple stock code I had written for VP 10 years ago will not work in FP. On top of it, FP has "memory slots" that is limited to a max of 32 items, and I am wondering if a stock VBScript code snippet will even work that creates/writes/reads a simple text file.

If someone wants to do the research on that and try it out, It will save a lot of time for me.

My timer and debug write setup - having all that repeating code written to the debug file makes it very tough to find and figure things out. At the moment, my code stores the initial physics on a flipper hit, and then stores the final flipper physics the time the ball leaves the flipper. Once the flipper is no longer in a "hit" state, it then writes those values in the Debug text, and includes a time stamp so people can call the text file up and find what they are looking for quite easy. This is the start at least, I have a lot of things to add.

I intend to do the following things
1. Have far more info on the various physics written to the text file with a key press to the debug text file
2. Have a separate file (if possible) that can store various additional settings with copy and paste code.
3. Have a more simplistic system than the built in menu that allows you to adjust basic physics "on the fly". Most people I have talked too have found the BAM menu is too complex for them, so a menu for dummies type thing.
4. A basic idea is to not have generic physics, or multiple bounce control, but instead to have set physics for the various flipper models (like a set for the T1 Flipper, a set for the T2 flipper etc) as the flippers included in FP are very different from each other and have completely different dimensions, tip size, base size, mass etc

See what time I have tonight, maybe get started on that.

_________________
_____________________________________

Latest projects and rants at My Facebook Page
_____________________________________

Latest Project: fpxEngine


Top 
 Profile  
 
 Post subject: Re: BAM Dynamic Flipper Breakthrough !!
 Post Posted: Thu Dec 13, 2018 10:06 pm 
Offline

Joined: Mon Jan 27, 2014 12:36 pm
Posts: 2859
Location: Ontario, Canada
Sounds Great Blue

Here is template for people to try in their tables.
It is basically the same as above, but I removed a lot of the debug stuff. To provide just a straight forward
ready to go template. Just copy in paste under "option explicit"

I substituted this for the previous one we had in Jaws and I really like it... the bounce and aiming seem great!

Addendum: LOVE it in CFTBL, Batman Joker , Jaws and Indy! :shock:

Code:
' HOW TO COPY DYNAMIC FLIPPERS TO YOUR TABLE
' __________________________________________
'
' Some of the guys have requested a way for a novice to add dynamic flippers to other tables. 
' I have adjusted the flipper settings to work with the XML file that has been added below.  I recommend
' copying the XML along with the flipper settings. I actually tweak the settings very minimally in my custom
' physics tables so the settings should work for you.  Just copy all the lines of this script from
' "HOW TO COPY DYNAMIC FLIPPERS TO YOUR TABLE" down to "End of Dynamic Flipper Settings".  Then paste
' into your table BELOW THE LINE that says "Option Explicit" in the script.  I recommend changing the
' strength of the main slingshots located just above the flippers in the table editor to their minimum
' setting for the table to play better. .Some additional guidance is provided in the "FLIPPER OMEGA" and
' "BOUNCE CCONTROL" sections below.  You may need to adjust the "MinOmega" in the "FLIPPER OMEGA" section 
' below.  You should try the rest of the content to see it it works for you. 

'=============================== PHYSICS XML ===========================
'<?xml version="1.0" encoding="utf-8"?>
'<document>
'  <!—Custom Physics for Medieval Madness -->
'  <physics fps="296" threaded="1"></physics>
'  <ball newtonDamping="0" mass="72" gravity="5300" damping="1.25"></ball>
'  <flipper releaseOmega="18" rotationSpeedChart="{0.0,100.0}[0.0,100.0]" newtonDamping="1" mass="20150" omega="43" moeMethod="0"
'           leftXoff="0" leftYoff="1500" leftZoff="0"
'           rightXoff="0" rightYoff="1500" rightZoff="0"></flipper>
'  <bumper impulse="90.0" impulseRandomness="0" vectorRandomness="6"></bumper>
'  <autoplunger mass="20000.0" force="60000.0"></autoplunger>
'  <diverter mass="10000.0" omega="33.0"></diverter>
'  <gate mass="5.0" gravity="2500.0" damping="0.25"></gate>
'  <kicker impulse="1000.0" vukImpulse="1400.0" impulseRandomness="2" vectorRandomness="1"></kicker>
'  <plunger mass="20000.0" force="30000.0"></plunger>
'  <slingshot impulse="500.0" impulseRandomness="15" vectorRandomness="3"></slingshot>
'  <spindisk mass="10000.0" angularDamp="0.33" linearDamp="0.25"></spindisk>
'  <spinner mass="60.0" gravity="100.0" angularDamp="0.25" angularAccel="5.25"
'           spinDampLoose="0.55" spinBackLoose="1.70"
'           spinDampNorm="0.75" spinBackNorm="1.80"
'           spinDampTight="0.95" spinBackTight="1.90"></spinner>
'  <emkicker mass="10000.0" omega="80.0"></emkicker>
'  <varitarget mass="500.0" damping="0.9" tension="3.0" return="15.0"></varitarget>
'  <magnet impulse="10.0" impulseRandomness="2"></magnet>
'  <nudge impulse="120.0" impulseRandomness="25.0" warningLevel="260" leftAngle="60" upAngle="0" rightAngle="320"
'         vectorRandomness="5" visualDistance="1" waitPeriod="300" maxBallVelocity="500.0"></nudge>
'  <defaultMat softnessCoef="0.02" elasticCoef="0.1" staticFriction="0.02" kineticFriction="0.02"></defaultMat>
'  <playfieldMat softnessCoef="0.03" elasticCoef="0.1" staticFriction="0.025" kineticFriction="0.015"></playfieldMat>
'  <metalMat softnessCoef="0.01" elasticCoef="0.1" staticFriction="0.01" kineticFriction="0.01"></metalMat>
'  <woodMat softnessCoef="0.03" elasticCoef="0.15" staticFriction="0.03" kineticFriction="0.02"></woodMat>
'  <plasticMat softnessCoef="0.02" elasticCoef="0.2" staticFriction="0.02" kineticFriction="0.01"></plasticMat>
'  <rubberHardMat softnessCoef="0.08" elasticCoef="0.42" staticFriction="0.04" kineticFriction="0.055"></rubberHardMat>
'  <rubberIntMat softnessCoef="0.1" elasticCoef="0.52" staticFriction="0.05" kineticFriction="0.065"></rubberIntMat>
'  <rubberSoftMat softnessCoef="0.12" elasticCoef="0.62" staticFriction="0.06" kineticFriction="0.075"></rubberSoftMat>
'  <gateMat softnessCoef="0.05" elasticCoef="0.65" staticFriction="0" kineticFriction="0"></gateMat>
'  <kickerMat softnessCoef="0.01" elasticCoef="0.05" staticFriction="0.8" kineticFriction="0.8"></kickerMat>
'  <rampMat softnessCoef="0.01" elasticCoef="0.01" staticFriction="0.01" kineticFriction="0.01"></rampMat>
'  <plungerMat softnessCoef="0.04" elasticCoef="0.55" staticFriction="0.02" kineticFriction="0.02"></plungerMat>
'  <spindiskMat softnessCoef="0.05" elasticCoef="0.5" staticFriction="1.5" kineticFriction="2"></spindiskMat>
'</document>
'=============================== PHYSICS XML ===========================

' === Dynamic Flipper Settings ===


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Start of Monitoring Code''''''''''''''''''''''''''''''''''


Dim BallTrajectory


Sub NewtonPhysicsTick()
   BallTrajectory  = Atn2( xBAM.Ball.Velocity.X, xBAM.Ball.Velocity.y )
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   
      AddDebugText "ball.Speed: " & ball.Speed
      AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
      AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
      AddDebugText "xBAM.Ball.Velocity.X: " & xBAM.Ball.Velocity.X
      AddDebugText "xBAM.Ball.Position.X: " & xBAM.Ball.Position.X
      AddDebugText "BounceMix: " & BounceMix
End Sub

' Convert X, Y velocities to ball trajectory angle
Const RadToDeg = 57.295779513082320876798154814105 
Function Atn2(x, y)
   If x > 0 Then
      Atn2 = Atn(y / x) * RadToDeg
   ElseIf x < 0 Then
      Atn2 = 180 - RadToDeg * Atn(y / -x)
   ElseIf y > 0 Then
      Atn2 = 90
   Else
      Atn2 = -90
   End If
   Atn2 = Atn2+90
End Function


Sub MaxSpeedTimer_Expired()  'you must add a timer in table editor called "MaxSpeedTimer"
   MaxSpeedTimer.Set False
   maxballspeed = 0
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''End of Monitoring Code''''''''''''''''''''''''''''''''''''''''''''''' 

Const BAM_VERSION = 0
AddDebugText BAM_VERSION

If BAM_VERSION > 179 Then xBAM.FixScore

If BAM_VERSION => 233 then
Dim RightFlipperExt,LeftFlipperExt            ' Needed for BAM
 Dim omegaCorrection
xBAM.BallSpeedLimit = 2500
End If   
   

Sub BAM_Init()
   If BAM_VERSION < 233 then Exit Sub
   Set RightFlipperExt      = xBAM.Flipper("RightFlipper")
   Set LeftFlipperExt       = xBAM.Flipper("LeftFlipper")
   RightFlipperExt.Omega    =         47
   LeftFlipperExt.Omega     =         43
End Sub


' FLIPPER OMEGA

' You may want to adjust the strength (also called omega) of the flippers when you add dynamic flipper 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 "MinOmega" unchanged and then go on to "BOUNCE CCONTROL" below.

If BAM_VERSION => 233 then
   const MaxOmegaL  = 43  ' Omega at base of flipper.  Must be > MinOmega. Default = 45
   const MinOmegaL  = 32  ' Omega at tip of flipper. Must be < MaxOmega. Default = 31.5
    const MaxOmegaR  = 47  ' Omega at base of flipper.  Must be > MinOmega. Default = 45
   const MinOmegaR  = 32  ' Omega at tip of flipper. Must be < MaxOmega. Default = 31.5
End If

Dim BounceMix
Dim ball_to_flipper_angle
''''''''''''''''''''''''''''''''''''''''''''Right Flipper Prehit Code'''''''''''''''''''''''''''''''''''''''

Sub RightFlipper_prehit()
If BAM_VERSION < 233 then Exit Sub
   ball_to_flipper_angle =  Atn2( RightFlipperExt.BallHSpeed, RightFlipperExt.BallVSpeed )
   
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If xBAM.Ball.Speed <= 200 then BounceMix = 1 'Ball Speed Measures 150 rolling down left fliper from cradled ball so this should capture it
   If xBAM.Ball.Speed > 200  then  BounceMIx = 2
     

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 "RightFlipperExt.ContactPoint: " & RightFlipperExt.ContactPoint
   AddDebugText "RightFlipperExt.Mass : " & RightFlipperExt.Mass
   AddDebugText "RightFlipperExt.Omega : " & RightFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "RightFlipperExt.Angle: " & RightFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   
End Sub


'''''''''''''''''''''''''''''''''''''''''''''''Left Flipper PreHit Code'''''''''''''''''''''''''''''
 
Sub LeftFlipper_prehit()
   Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
   If xBAM.Ball.Speed <= 200 then BounceMix = 1 'Ball Speed Measures 150 rolling down left fliper from cradled ball so this should capture it
   If xBAM.Ball.Speed > 200  then  BounceMIx = 2
If BAM_VERSION < 233 then Exit Sub
   ball_to_flipper_angle =  Atn2( LeftFlipperExt.BallHSpeed, LeftFlipperExt.BallVSpeed )
   
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 "LeftFlipperExt.ContactPoint: " & LeftFlipperExt.ContactPoint
   AddDebugText "LeftFlipperExt.Mass : " & LeftFlipperExt.Mass
   AddDebugText "LeftFlipperExt.Omega : " & LeftFlipperExt.Omega
   AddDebugText "xBAM.Ball.Speed: " & xBAM.Ball.Speed
   AddDebugText "xBAM.Ball.Velocity.y: " & xBAM.Ball.Velocity.y
   AddDebugText "xBAM.Ball.Position.Y: " & xBAM.Ball.Position.Y
   AddDebugText "LeftFlipperExt.Angle: " & LeftFlipperExt.Angle
   AddDebugText "ball_to_flipper_angle: " & ball_to_flipper_angle
   
End Sub


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' BOUNCE CCONTROL


' Bounce control is the amount of bounce the ball makes when it hits the flippers.  You may want to leave these settings unchanged. 
' I would suggest small changes here of "base_elasticCoef" and "expected_ball_speed_after_hit".

'(Note that bounce control over rides flipper elasticity listed in the XML. See lines "RightFlipperExt.Omega ="/"RightFlipperExt.Omega=")


Sub OnPreHitFlipperSettings(FlipperExt)
   If BAM_VERSION < 233 then Exit Sub
 'Exit Sub 'turn if off no bounce control
If BounceMix = 1 then OnPreHitFlipperSettings_nobounceControl(FlipperExt)
If BounceMix = 3 then OnPreHitFlipperSettings_bounceControl_verticalAverge(FlipperExt)
If BounceMix = 2 then OnPreHitFlipperSettings_bounceControl(FlipperExt) 'Original Rav Bounce
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''Original Ravarcade Bounce Control'''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnPreHitFlipperSettings_bounceControl(FlipperExt)
   
   If BAM_VERSION < 233 then Exit Sub
   ' Params to tweak
   const base_elasticCoef                        = 0.90 'george .95 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 370 '400 calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.20 ' 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.15 ' if flipper is not in starting point, reduce elasticCoef by 20%
 
   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
''''''''''''''''''''''''''''''''''''''''''''''Ravarcade Bounce Control Based on average vertical velocity'''''''''''''''''''

Sub OnPreHitFlipperSettings_bounceControl_verticalAverge(FlipperExt)
   ' Params to tweak
   const base_elasticCoef                        = 0.95 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 400  ' calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.20 ' 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.15 ' if flipper is not in starting point, reduce elasticCoef by 20%
   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
''''''''''''''''''''''''''''''''''''''''''''No Bounce Control Reset Values from xml'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub OnPreHitFlipperSettings_nobounceControl(FlipperExt)

   RightFlipperExt.SetMaterial       0.62,        0.12,       0.06,      0.075
   LeftFlipperExt.SetMaterial       0.62,        0.12,       0.06,      0.075
   
End Sub


 ' ============================== CUT HERE END =================



It's either the Kilkenny Beer or this code Rocks !!
https://youtu.be/ZJ_DeVg1UgE


Last edited by Gimli on Sun Dec 16, 2018 2:45 pm, edited 1 time in total.

Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 225 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 23  Next

Board index » Future Pinball » BAM corner


Who is online

Users browsing this forum: No registered users and 9 guests

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to: