Wikis > Visual Pinball Knowledge Base > Adding ball shadow

By Nunizzu – ref :

First you need the ballshadow primitive(s), their texture and material; you can take everything from this test table:

Ballshadow Test Table

Now it comes the scripting, you can copy paste this in your tables:

‘ *********** BALL SHADOW *********************************
Dim BallShadow
BallShadow = Array (BallShadow1)

Sub BallShadowUpdate_timer()
Dim BOT, b
BOT = GetBalls

‘ hide shadow of deleted balls
If UBound(BOT)<(tnob-1) Then
For b = (UBound(BOT) + 1) to (tnob-1)
BallShadow(b).visible = 0
End If

‘ exit the Sub if no balls on the table
If UBound(BOT) = -1 Then Exit Sub

‘ render the shadow for each ball
For b = 0 to UBound(BOT)
If BOT(b).X < Table1.Width/2 Then
BallShadow(b).X = ((BOT(b).X) – (Ballsize/6) + ((BOT(b).X – (Table1.Width/2))/7)) + 10
BallShadow(b).X = ((BOT(b).X) + (Ballsize/6) + ((BOT(b).X – (Table1.Width/2))/7)) – 10
End If
ballShadow(b).Y = BOT(b).Y + 20
If BOT(b).Z > 20 Then
BallShadow(b).visible = 1
BallShadow(b).visible = 0
End If
End Sub

Now I will explain that code, which is based on JP’s rolling sound routine.

You need as much ballshadows primitives as the tnob, defined in the Jp’s rolling sound routine. So, for example

Const tnob=3

This means that we have maximum 3 balls during the gameplay, so you need 3 ballshadow primitives (one for each ball). The first part will become

Dim BallShadow
BallShadow = Array(Ballshadow1,Ballshadow2,Ballshadow3)

So you have to duplicate the primitive “Ballshadow1”, included in the sample table above, as many times as the total number of balls (tnob).

Finally, to make it work, you need to:

-add a timer, always enabled and with a low interval (I set it at 10 ms): name it BallshadowUpdate

-change the instances of Table1 with the name of the Table you find in the Vp Editor (default name is table1, but it may change).

-define the ballsize (default value is 50) or replace the ballsize instances with the value 50 or so.

Note: some authors are using an older version of this code, so please update it with the new one. It fixes some situations when the ball gets destroyed (e.g. it drains) but the shadow is still visible above the pf.

This is the standard method, it works for 90% of the tables, but there are some cases where you need to hide the shadow because a fakeball is used and you don’t want to display its shadow (or mute the rolling sound).

Category: Tags:


Log in with your credentials


Forgot your details?

Create Account

The Vpinball app