Tombola Balls
I’ve been working on a fun little Unity project that combines the visual effects of a fluid dynamics simulation with an integration to the Twitch API. Sounds like a bit of an odd combination, right? This project has formed part of my ongoing support for @laylacodesit and her Live-Coding Twitch channel,
Unlike the blow-by-blow instructions that you’ll find in my other articles, this “Projects” section is intended to be a tour of some of the projects that I’ve been working on. If you want to replicate these projects, you’ll need to figure out the implementation details yourself, but hopefully, they can be a source of useful hints and inspiration for folks.
Raffle Tombola Lotto Draw Drum for Raffle Tickets, Balls, Discs. Drum Door -Easy to open with a Secure Brass Catch Fitting. Drum in Balanced on the Stand so No Handle needed. Drum Size: 30cm x 16cm. Perfect forFundraising events, fetes, club draws, charities, schools, clubs, parties, pubs - anywhere! Metal Bingo Game Set Cage Tombola With Chips Balls Cards. Condition is 'Used'. Shipped with USPS Priority Mail.This set is in excellent condition, only used a few times. Ball N45 was replaced with a spare, so it is handwritten, but all the balls are there. FixtureDisplays Metal Raffle Drum Spin Casino Bingo Lottery Party Lucky Draw Fundraiser Tombola 10006-NF No. Bingo Board, Bingo Balls, 18 Bingo Cards,.
The idea is straightforward:
- Viewers of the Twitch channel have the opportunity to participate in a prize-winning competition, by entering the command “!prizedraw” in the chat window.
- Over the course of the broadcast, multiple viewers will add their “entry” into the raffle. This manifests in the form of a tombola ball (only one per viewer)
- Using simulated physics, the barrel rotates, mixing the balls together randomly.
- When the prize-draw is made, barrel rotation is stopped (using a keyboard hotkey) and a “rod” object, projects upwards through the bottom of the barrel and scoops up a single winning ball.
- A collision zone, located near the centre of the barrel, detects the presence of the winning ball and triggers the “you’re a winner” behaviour.
- An animation is used to pan the camera in for dramatic effect and the winning viewer has their name displayed in the scene.
Solution ingredients
The overall solution brings together a number of elements:
- Unity 2019.2.x project
- Using OBS Studio, the Unity application is screen-captured and composited into an OBS scene, before being broadcast to viewers.
- A plain-colour background is set as the Unity background, which is then chromakey cut-out using OBS, just like we do with a person in front of a green-screen (except magenta was used instead of green).
- When viewers submit their entry, thACey get to see a “virtual ball”, that represents their competition-entry, projected into a slowly spinning virtual drum/barrel.
- The ball is wrapped in a texture of the viewers Twitch-Avatar. This helps to personalise their interaction with the competition.
- The texture is obtained on the fly, by downloading the avatar image directly from Twitch, using TwichAPI calls to locate the image link.
- To emulate a lottery tombola, the Unity physics engine is used to simulate the balls bumping and colliding around inside the barrel.
- To add novelty and visual interest for the viewers, the barrel also contains a fluid simulation.
- The fluid is both a visual and physical simulation, meaning that it interacts with both the barrel and any balls that are added by viewers.
- The Unity application runs a client service that hooks-up to the Twitch API and listens for commands.
- This is very similar to how a typical “Twitch bots” works.
- Unity uses C# for scripting, meaning that I could leverage the popular OS library TwitchLib that takes care of the details of integrating with the various Twitch APIs.
- In fact, life gets nicer still, as in 2018 a Unity-specific wrapper for TwitchLib was made available by that OS team.
- This is represented by the single file twitchlib.unity.dll that can just be dropped anywhere into the Unity project asset folder structure.
- In fact, life gets nicer still, as in 2018 a Unity-specific wrapper for TwitchLib was made available by that OS team.
- TextMeshPro is used to display messages onscreen, such as “viewerXYZ has just participated”.
A word of warning for anyone who fancies having a go at making their own version of this project: Running a complex physics/fluid simulation, whilst also using OBS to generate and encode a Livestream, carries a significant computational overhead. You’re going to need a well-specced gaming machine to pull this off.
Below is clip from Twitch showing an early version of the tombola project:
… and this is a revised version, that was themed for international talk like a pirate day!
Obi Fluid
Obi Fluid is a super-cool paid-for asset, created by VirtualMethodStudio and available from the Unity Store. It provides a tonne of functionality used for simulating various fluids using a particle system.
- Documentation for Obi Fluid can be found at VirtualMethodStudio : Fluid Setup
- A support forum can be found at VirtualMethodStudio : Forum
Drawing from the demonstration material and documentation, I found that I was able to produce immediate and impressive-looking results.
However, I subsequently found that getting my fluid to look and behave the way I wanted, took me hours of fiddling - particularly around the “blueprint” for a particular fluid (a definition file containing settings that describe how a fluid behaves).
This is not a fault or criticism of ObiFluid - it’s just a complex piece of software with a great many settings and effect combinations.
- This is a really useful guide to help visualise what the settings mean : ObiFluid guide to blueprint settings
In particular, I found that finding an acceptable setting for particle “resolution” to be a fiddly challenge. There is no correct fits-all solution; an appropriate resolution needs to be matched with the size of your virtual world and the number of particles in the simulation - I still can’t see a better way through this, other than time-consuming trial and error.
The importance of a simplified mesh collider
With the addition of an “Obi Collider” component, the particles, that comprise an ObiFluid fluid, interact with a mesh collider just fine. Ultimately this is how we get to see a simulated-fluid contained and sloshing around the inside of a “barrel” model.
When it comes to Unity, relatively speaking I’m still quite the noob. A lesson that took me a lot of pain and a long time to learn, is that having an overly-complex physics collider mesh absolutely ruined the performance of the simulation and the FPS of the project.
In this project, I initially used a collider-mesh model, with what I assumed was fairly basic geometry, and it still completely trashed performance.
Dropping to the bare minimal mesh, that I now use, meant that I could comfortably go from simulating fluid with about 500 particles, all the way up to about 3000 or even 4000 at a push - whilst running at a solid 60FPS and whilst simultaneously hosting a Livestream and all the other computationally expensive work that goes hand-in-hand with that!
So for the benefit of anyone following in my footsteps - my learning is that the visual mesh and the physics-collider mesh don’t need to be the same.
Use an appropriately detailed mesh for the visual representation of our object, as usual.
Work hard to create a super-simplified second mesh that will be used for the physics collider model.
I created my collider mesh through a combination of a manually-made simple model, combined with several experimental iterations using the Blender Decimate Modifier.
- Here is what the two meshes that I used to create the tombola look like.
- Aside from the vastly simplified geometry, notice also, that I did not include any 3D surfaces that represent the outside to the tombola - we are only interested in modelling collisions inside the barrel, so any other complexity is unused and computationally wasteful.
Physics engine “tunnelling” is a nuisance
During development, I had the problem of a “leaky barrel”.
Even though the barrel model had no gaps in the geometry, the simulated-liquid particles were gradually passing through the collision mesh and falling away into the endless abyss below.
This was a challenge that took me some time to resolve; even getting to a point where I actually understood what was causing the problem, took some time.
This issue boiled down to something that, with the benefit of hindsight, is actually a common issue found in game-engine physics - something referred to as “physics engine tunnelling”.
“Tunneling” can be observed when a second object, that is moving in such a way that it should be expected to collide with the first object - passes straight through the first object.
Typically, this issue manifests when:
- a second object moving with relatively high velocity.
- the physics engine not running at a frequency high enough to provide sufficient positional fidelity.
- an object is positioned by setting its transform manually, rather than through an animation.
What transpires is that the second object effectively “teleports” passed the first object and a collision is not registered by the physics engine.
- This forum thread is a useful reference to further explore
Tunnelling occurs because:
- In a game-engine, 3D objects are not “solid”.
- Objects are made up of infinitely thin flat surfaces and collision detection is based upon those surfaces.
- Similarly, when a 3D model moves through 3D space, it doesn’t actually physically move from one place to another with infinite “presence”, as a real-life object would. Instead, the game engine effectively “teleports” the object from one position to the next.
- The “simulation rate” at which this happens depends on how the physics engine has been configured - but can normally be expected to happen with a much greater frequency than the FPS of the rendered image.
- The physics engine can be instructed to attempt to mitigate the effect (using “continuous collision detection” setting).
- You can read about this here at Unity Docs : Continuous Collision Detection
- Even with these settings active, tunnelling was still a problem in this project. I’m not sure, but I think it was because my various objects had rotational motion and not linear velocities, meaning the engine couldn’t figure out collisions properly.
There were two settings that made a night and day difference to the problem of tunnelling (although I never 100% fixed the leaking problem). In the component settings for my rotating “barrel” object:
- In the “animator” component, set “Update mode” to “Animate Physics”.
- In the “rigidbody” component, set “collision detection” to “continuous”.
What is tombola
The traditional form of Tombola came from Italy in the eighteenth century, but has since evolved into various forms. In essence it is a type of raffle where prizes are pre-assigned to certain numbers, and players draw a number (in the form of a numbered ball or ticket) to determine if they have won a prize.
In the context of fundraising, tombola has evolved to prizes being contained in numbered bottles or jars, and players draw a number and win the corresponding jar.
Forms of tombola
A wine tombola will have various bottles of wine (which can be wrapped in brown paper so people don’t know what they are, or left bare to everyone can see the labels), with a few high-end expensive wines as the draw-card. Players might pay $10 for a ticket, in the hope they win a $50 bottle of wine.
A bottle tombola will have a variety of bottled goods – from shampoo to passata to pickles to jams – usually all pantry items, and the price for a ticket might be $2-$5.
Most commonly, tombola prizes are jars filled with assorted items. Part of the fun of tombola is the huge range of items that the jars can contain, and I have provided a list below of more than 75 things you can put in a tombola jar, including some very special prizes for school kids that will cause a lot of excitement.
How to run a tombola
Tombola can almost be 100% profit if you get families within your school or community to provide the pre-filled jars. As long as they are filled with non-perishable items, you can start preparing the jars months in advance of your fundraising event, leaving minimal work for the day.
Jars can be second-hand as long as they are clean and have no label. They can be a range of sizes and shapes, and while you can leave them bare, they look extra nice when all the lids are covered with a matching cloth cover.
A great way of getting tombola donations is to ask students to bring a filled tombola jar in lieu of a gold coin donation for a free-dress/mufti day. People often have items around the house they can fill their jars with – there is no requirement for them to buy items specifically.
Once all the jars have been received, each must be numbered. You can simply stick a raffle ticket on each, or make special stickers with you school or fete logo which you hand number. Either way, you need to have the corresponding raffle ticket (or numbered ball) in a barrel or bucket for players to draw from.
You can decide if every ticket drawn wins a prize or if some of the numbers have a consolation prize (a lollypop) or no prize at all. Some recommendations suggest that 1 in 4 tickets win a prize, but I personally believe that all players should win a prize.
The cost to play (ie draw a number from the barrel) is a set price (ie $2 or $5) but it is fine for the value of the prizes to vary wildly – as it is the ‘valuable’ jars that act as a draw card. Make sure you promote the more unusual and valuable tombola prizes in advance to build excitement.
On the day of your event, all you need are tables to display your jars and a barrel or bucket full of tickets/numbers for players to draw from.
Hint: make sure you put your jars out in numerical order (not random). If the stall gets busy, you don’t want to be looking through 250 jars to find the correct one.
Suggestions for tombola jars
New/Pre-loved toys
Lego
Marbles
Costume jewellery
Barbie doll clothes
Temporary tattoos
Shopkins etc
Matchbox cars
Toy soldiers/dinosaurs/farm animals
Jokes
Skipping rope
Ping pong balls or tiny bouncy balls
Assorted goodies you get in party bags
DIY (include recipe/instructions in a small snap-lock bag folded at the top of the jar)
Non-perishable Ingredients for slime
Ingredients for cookies and brownie
Ingredients for playdough
Items to make pet rocks (smooth pebbles, paint, googly eyes etc)
Compilations
Gardening gloves, seed packets etc
Pencils, erasers, sharpener, tiny notebook, paper clips etc
Sewing kit: threads, tiny scissors, pins, needles, tape measure, thimble etc
Pamper kit: emery board, nail polish, face mask, bath bomb
Emergency kit: mini torch, mini screwdrivers, safety pins, tape etc
First aid kit – bandaids, eye wash, anti-bacterial cream etc
Make fresh just prior to event
Home-made sugar scrubs
Lollies or lolly pops (very popular and easy to make)
Chocolates
Home-made chutneys and jams
Tombola Band
Fete related prizes
Vouchers for free rides
Meal/ice cream vouchers
Extra raffle tickets for the raffle
‘Fete dollars’ to spend at any stall at the fete
Extra special school prizes (if a non-school person win these, you can always let them pick again)
Win your entire class a pizza party
Win your entire class a free icecream from the canteen
Win your entire class a movie afternoon
Win your school a free-dress day (you get to pick the theme)
Win your teachers a dress-up day (you get to pick the theme)
Win your class an extra-long recess
Household
Elastic bands, tiny bulldog clips or paperclips
Origami paper
Hair elastics, scrunchies or hair clips (new)
Push-pins/thumb tacks
Party poppers
Bubble mix
New socks
Balloons
Water balloons
Tiny novelty erasers
5 cent pieces or $2 coins
Scratch’n’win tickets
A rolled $20 or $50 note
Tea-light candles
Fridge magnets
Glow sticks
Chalk
Beach sand with beautiful shell hidden inside
Beauty
Bath salts
Bath gel balls
Exfoliating gloves
Face masks
Lip gloss or balm
Nail polish
Potpourri
Craft
Buttons
Tubes of glitter
Glitter glue
Beads
New pencils or crayons
Pom poms
Tiny bows
Googly eyes
Pipe cleaners
Washi tape
Brad pins
Stamps
Sequins
Stickers
What is your favourite tombola idea?
Tombola Balls Candy
Disclaimer: Some of the links on this site are affiliate links, meaning that at no cost to you, I may earn a small commissionif you make apurchase. This helps me meet costs associated with Fundraising Mums – thank you for your support.