Tutorial Physics/XML A Simple Way to Add Physics to Any Future Pinball (FP) Table with Original Physics

GeorgeH

Flippered Out
Site Supporters
Joined
May 3, 2016
Messages
2,659
Solutions
6
Reaction score
2,118
Points
145
Favorite Pinball Machine
Attack From Mars
This tutorial can still be used although there is a new tutorial for FizX Lite Edition that you should consider using that is available here. It does require a little more work to add to your table.

Note: This tutorial requires that you have Better Arcade Mode (BAM) installed.

I wrote this tutorial assuming you know very little about FP so anyone can use it. There really is no such thing as perfect physics. A lot depends on your personal preferences. I have created physics for tables for some time now and quite a few people appear to like it although some increase the table slope to make the table play faster. Anyway, I think everyone will like these physics better than the terrible physics of the original FP program. To create this tutorial, I copied 20 tables selected at random to a new folder and started experimenting. I found an xml that works well on all 20 tables.

Select all the code below and copy it to the clipboard using Ctrl "C". Open the script for a table from the FP editor. Paste (Ctrl "V") the code below the line that says "Option Explicit" and save the changes. The xml code included below will be green when added to the script which means that it is saved as a comment but BAM will still use it. You must save changes and close the FP editor before you play the table in order for the xml code work.

The xml code works best when the table slope is set to 6.8 although you may want to increase this if you want the table to play faster. I posted a screenshot of how to change the slope below.

How to Make Adjustments

There are a few adjustments that may be needed after you save the code to the script and change the slope. You will have many tables where you won't need to make any of these adjustments. I included these directions to cover the exceptions.

Of the 20 tables I tested, two needed to have the strength of a vertical up kicker (VUK) adjusted. You can tell the VUK needs to be adjusted when it won't kick the ball hard enough to make it go all the way up to the ramp. The ball usually ends up being kicked repeatedly or the ball may just be kicked once and drop back down into the kicker. I posted a screenshot of how to adjust the kicker below.

The plunger on two tables only launched the ball partially up the launch lane and then the ball rolled back down to the plunger. When this happens, you need to increase the strength of the plunger. I posted a screenshot of how to adjust the plunger below.

There may be times when you may want to adjust the strength of the slingshots. None of the 20 tables I tested had specific problems caused by the strength of the slingshots. However, I would have adjusted a couple to make the table play better. I posted a screenshot of how to adjust the slingshots below.

None of the tables I selected had problems with the ramps. My experience with other tables is that the ball can partially go up a ramp and then roll back down. When you have this problem, you can't hit the ball hard enough so it will go all the way up the ramp. The usual fix is the increase the strength (omega) of the flippers. If this happens, open the script and scroll down to the section that looks like this:

const MinOmega = 30
const MaxOmega = 45


MinOmega is the strength of the flipper at the tip of the flipper. MaxOmega is the strength of the flipper at the base of the flipper. Midpoints on the flipper have strengths in between the values for MinOmega and MaxOmega. You can adjust MinOmega and MaxOmega by changing the blue numbers as shown in the example above. I usually adjust the MinOmega to make the flipper hit harder. Sometimes I want to cradle the ball and allow it to roll down the flipper to a midpoint and then hit the flipper to make a shot. Adjusting MaxOmega can help make that shot although you probably won't to change MaxOmega very often. There are some additional directions that have been saved to the comments in the script.

This concludes the tutorial. Please post any questions you have below.

Edit 11/15/20: It seems that TerryRed and I produced nearly the same tutorial and posted it on the very same afternoon without the knowledge of what the other was doing. Like Terry says, "Great minds think alike". Terry's physics are different from mine so you might try both:


Note that the code can be applied to electromagnetic (EM) tables as well as solid state.

The dynamic flippers will work on tables that have more the the two main flippers but the dynamics will only affect the main flippers. I always add dynamic flippers to all the flippers on a table but the improvement on the upper flippers is not as dramatic as the main flippers.

I always tweak the xml also so it is specific to the tables that I post but that is beyond what most folks will want to do. This generic xml works well enough to get you to 90 to 95 percent of the way there.

____________________ Adjusting Table Slope ______________________________ Adjusting Kicker Strength ___________
Slope.jpg___ Kicker.jpg

__________ Adjusting Plunger Strength __________________________ Adjusting Slingshot Strength __________
Plunger.jpg___Slingshot.jpg

Code:
'=============================== PHYSICS XML ===========================
'<?xml version="1.0" encoding="utf-8"?>
'<document>
'  <physics fps="296" threaded="1"></physics>
'  <ball newtonDamping="0" mass="80" gravity="7100" damping="0.9"></ball>
'  <flipper rotationSpeedChart="{0.0,100.0}[0.0,100.0]" newtonDamping="1" releaseOmega="18" mass="20150" omega="43" moeMethod="0" leftXoff="0" leftYoff="0" leftZoff="0" rightXoff="0" rightYoff="0" 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="0.010" gravity="100" 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="700.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="40.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="250" 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.32" staticFriction="0.04" kineticFriction="0.055"></rubberHardMat>
'  <rubberIntMat softnessCoef="0.1" elasticCoef="0.42" staticFriction="0.05" kineticFriction="0.065"></rubberIntMat>
'  <rubberSoftMat softnessCoef="0.12" elasticCoef="0.52" 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 ===

Const BAM_VERSION = 0 ' Note that BAM 233 implemented dynamic flippers but this table uses
                             ' "xBAM.CreateAllExt" which requires BAM 254.
AddDebugText BAM_VERSION

If BAM_VERSION => 254 then

Dim omegaCorrectionL
Dim omegaCorrectionR
Dim BounceMix
xBAM.CreateAllExt
End If

' 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 26 and 33.  This is not a strict rule
' but it gives you an idea of approximate values that work for me.  You need to leave the section below "MaxOmega2"
' unchanged and then go on to "BOUNCE CONTROL" below.below.

If BAM_VERSION => 254 then
   const MinOmega  = 30  ' Omega at tip of flipper. Must be < MaxOmega.        Default = 30
   const MaxOmega  = 45  ' Omega at base of flipper.  Must be > MinOmega.     Default = 45

End If

Dim ball_to_flipper_angle

''''''''''''''''''''''''''''''''''''''''''''Right Flipper Prehit Code'''''''''''''''''''''''''''''''''''''''

Sub RightFlipper_prehit()
If BAM_VERSION < 254 then Exit Sub

    Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
    If xBAM.Ball.Speed <= 200 then BounceMix = 1
    If xBAM.Ball.Speed > 200  then  BounceMIx = 2

OnPreHitFlipperSettings(RightFlipperExt)
   omegaCorrectionr = MaxOmega - (RightFlipperExt.ContactPoint * ((MaxOmega - MinOmega)/1.2))
      If RightFlipperExt.ContactPoint < 0.0 then RightFlipperExt.Omega = MaxOmega
      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

'''''''''''''''''''''''''''''''''''''''''''''''Left Flipper PreHit Code'''''''''''''''''''''''''''''

Sub LeftFlipper_prehit()
If BAM_VERSION < 254 then Exit Sub
    Dim ball
   Set ball = xBAM.BallCloseTo(0,0)
    If ball.Speed <= 200 then BounceMix = 1
    If xBAM.Ball.Speed <= 200 then BounceMix = 1
    If xBAM.Ball.Speed > 200  then  BounceMIx = 2
If BAM_VERSION < 254 then Exit Sub


OnPreHitFlipperSettings(LeftFlipperExt)
     omegaCorrectionl = MaxOmega - (LeftFlipperExt.ContactPoint * ((MaxOmega - MinOmega)/1.2))
      If LeftFlipperExt.ContactPoint < 0.0 then LeftFlipperExt.Omega = MaxOmega
      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

' BOUNCE CONTROL

Sub OnPreHitFlipperSettings(FlipperExt)
   If BAM_VERSION < 254 then Exit Sub
If BounceMix = 1 then OnPreHitFlipperSettings_nobounceControl(FlipperExt)
If BounceMix = 2 then OnPreHitFlipperSettings_bounceControl(FlipperExt) 'Original Rav Bounce
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.  Replace the numbers in blue with numbers from one of the 12
' columns below.  I think the changes from one column 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.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

Sub OnPreHitFlipperSettings_bounceControl(FlipperExt)
   If BAM_VERSION < 254 then Exit Sub

' PARAMETERS TO TWEAK                    Default = Group 4.5 settings
   const base_elasticCoef                        = 0.61 ' very bouncy flipper rubber
   const expected_ball_speed_after_hit           = 231  ' calc elasticCoef to get desired ball speed after ball hit flipper
   const minimum_elasticCoef_to_scale_fast_balls = 0.04 ' 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

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

' === End of Dynamic Flipper Settings ===
 
Last edited:
OMG!... LOL! What are the chances of this happening... and on the same afternoon. I started typing this in the morning due to many requests on other groups.... but just just now went back to finish it off.... and I just now saw your link... haha. Great minds think alike dude!


So if anyone wanted another... almost similar (but more basic) tutorial for adding BAM new physics to a FP table.... you got two guides now.

I made mine so I could link to it for my FP and BAM Mega Guide.... then after I posted... I saw yours. Nice job.

I'll link to your guide for those who want more details about the physics settings... as I mention in my guide that you, gimli, and rav know more about those settings than me.
 
Great minds think alike dude!

let me say this too ... if I may.......don't hate me if I say this..... I say this only to encourage
"you all" should also make a guide on how to build a table, so that maybe someone starts building something, even a simple table, and not just modifying or adding, in my opinion it also takes people who build and not just to add,things.
 
OMG!... LOL! What are the chances of this happening... and on the same afternoon. I started typing this in the morning due to many requests on other groups.... but just just now went back to finish it off.... and I just now saw your link... haha. Great minds think alike dude!

I can't believe we both came up with the same thing on the same day! I wonder what the odds of that are?

Oh well, I guess the end user can try them both and decide which they like best.
 
Finally got around to trying out this upgrade, and so far I find it... pretty sweet indeed!

Specifically, I packaged your dynamic flippers (standard settings) with today's Bubble Bobble upload as a variant. Truly, the process could not have been easier for me, and it's hard to imagine anyone not appreciating the immediately-improved flipper play. :-D

So thanks for all your excellent work on this project, George. :clap:

And, hmm... just for gits and shiggles, I wonder how hard it would be to include Terry's and Shiva's flipper systems as well, giving the user a chance to choose between the three?

Or as an alternative, what if the code / XML could be kept as a universal resource sitting in the FP folder, such that all you'd need to do to upgrade a bunch of FP tables would be to add a command to call the external code. Something like that, anyway. Just pondering how easy it might be for FP users to quickly upgrade their table collections with the newer / better flipper systems.
 
I have no flipper system.... my guide is basically doing the same thing as George's here :)

The easiest "proper" way is to follow the guides. There is no quick fix that works for all tables as each table is different and needs adjustments to the table in the editor depending on how it was made and also what settings are used on the xml / dynamic flipper code.
 
There is no quick fix that works for all tables as each table is different and needs adjustments to the table in the editor depending on how it was made and also what settings are used on the xml / dynamic flipper code.
Yeah, I should have clarified...

Based on how Bubble Bobble went, and how George's own testing went, it looks like the (vast?) majority of tables will benefit even from a vanilla DF upgrade.

I get that some tables simply won't work or will require tweaking, but I'm thinking that for many table collectors, it may still be worth it to semi-automate the process. Like-- they can always note which tables have problems and set them aside for further adjustment, you know?

So, just wondering if a rough upgrade could be expedited across a user's whole collection in order to get the ball rolling, so to speak.
 
Last edited:
I get that some tables simply won't work or will require tweaking, but I'm thinking that for many table collectors, it may still be worth it to semi-automate the process. Like-- they can always note which tables have problems and set them aside for further adjustment, you know?

So, just wondering if a rough upgrade could be expedited across a user's whole collection in order to get the ball rolling, so to speak.
It would take someone smarter than I to figure that out. I have learned some code but not enough to do that. Maybe @ravarcade could figure something out. ...Maybe something similar to the way the "default.xml" file works? It would have to exclude tables that already have dynamic flippers including Shiva flippers and Lou has been working on something too though he is not finished.
 
I see a couple of problems.
- xBAM.CreateAllExt() has to be in inserted before the code and that is not being copied as far as I know. Hence at least at 1st time the default DF code will fail.

- the default DF structure can be copied (along some other stuff outside the scope of DF) as far as I can remember using shift+ctrl+c 3 times under dev - physics tweaks (or something like this. please correct me here as I can't test at the moment)
- like i just wrote, it is just the structure. DF is much more than this. Just compare to twilight Zone code...

I'll leave the solving of this problems to who can solved them though.

So, the simplest way I can think of is:

Open the table. C&P the whole code into a proper editor (notepad++ comes to mind) and c&p the code from a table like Twilight Zone, for example.

Obviously a pinned thread with specific instructions and caveats should be here. People have to know what it is to copy and where to paste it (plus things like the above xBAM.CreateAllEXT as mentioned above and eventual global variables needed along the way, etc. )
 
I would rather see a properly updated table when using newer physics solutions then a quick and dirty update. FP already has a bad reputation for physics.... the last thing we need are (respectfully) "half-assed" updates that will confuse people even more if the physics aren't up to a proper standard.

Better to take a bit of time to do things right. The BAM code and simple changes for specific tables can always be posted in a topic like this... and then the user can apply them themselves.... or tune then for their own liking.

The process is not that hard and does not take very long to add. The fine tuning is what takes the longest... and if someone is picky with what they like... then they would be doing this anyway.
 
I just remind myself that new physics can bring problems to some tables. Things kicker strengths or fine adjustments in some objects *might* be needed too. Testing required. All this needs emphasizing and falls in the caveats I mentioned before otherwise we end up in what TerryRed just posted.

How hard it'll be depends on a person skills. I for one avoid graphics like I avoid covid :D
 
How hard it'll be depends on a person skills. I for one avoid graphics like I avoid covid :D
Oh man, that would be nice... getting a vaccine one day, then the next day waking up and being a maestro at GIMP, PS, Blender...
 
A blanket vanilla upgrade might be nice, but I see the point about tweak requirements. The two recent VP table ports I've done went very different to each other. Of course converting VP code was tricky enough already, but when it came to implementing this tutorial, MahJongg slotted right in and worked nicely, but fire power tribute was a mess of weirdness initially. Even so, the improvements once it was all dialed in were definitely worth the effort.
 
General chit-chat
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: Flipper Hermann has left the room.
      Back
      Top