Ultimate Indie - Week 4 day 2 Boba Tycoon Prototyping
Starting the day off with a clear next path: writing the script to hold the value in a given container. I think it may also need to hold the density value? so water is 1 and ice is 0.8 and toppings are 1.2 or something so I can get the ingredients in the right order of the cup. I’ve thought roughly about liquids mixing but I think a drink is prettier when its got the layers separated.
Containing the liquid
So here is the new script:
I am actually going to remove the Volume class and make it into a ScriptableObject instead. Just with a name and density for now, this way I have a bunch of ingredients where I can adjust densities:
The IngredientVolume also needs a maxCapacity because the container needs to overflow at some point, and a currentVolume.
And then there needs to be some way to increase the volume and decrease the volume.
While writing this I realised how confusing this already is so I’m gong to rename some variables:
This is much more readable! IngredientVolume can actually go on but the jug and the cup since they both have a capacity for ingredients. I actually forgot to put [Serializable] above the class so I’ve added it so it can show in the inspector:
I’m probably going to change up the names even more so I can read it without confusion. Okay so the next step is to make the pouring script add some volume to the cup and log it out. I’m going to set what it adds to a public Ingredient for now to make it easier. It took a couple of tries and a bunch of Debug.Log()s but I got the number to increase when the pouring is on top!
Awesome! Now the next thing is to get the angle of the container in which it will start pouring out the liquid. This appears to be a fluid dynamics problem. I’m reading a thread on PhysicsForums about it and maybe I can make sense of it?
Or I could just add a circle collider that represents the top of the water that moves up and down and a collider at the lip to see if it passes that level? Interestingly the shader does some sort of calculation like that to make the liquid stay horizontal so maybe I can loo at how it does that.
Geometrically it can be worked out I think. After doing some googling and getting some foggy ideas, I think you’d need the volume of the cylinder (V=πr^2h) and the volume of the liquid inside. So if I have a cylinder that’s 20cm tall, and the radius is 4cm: that’s roughly 3.14 * (4 * 4) * 20. In my windows calculator it says that’s 1,004.8ml. Luckily that’s about the same as on this online Cylinder calculator. I’ll take their result since they are probably using more of pi’s numbers.
Capacity of Jug = 1005ml Volume to start = 1000ml
The tilt angle would be very small to get to the pouring - 0-5 degrees?
Capacity of Jug = 1005ml Volume = 500ml
The tilt angle would have to be just past 90/2 - 45-50 degrees?
Capacity of Jug = 1005ml Volume = 1ml
The tilt angle would be just under/around 90 degrees.
It seems kinda linear, but what will be tricky is the rate of flow for tilting past this point. Up to this point I can use this to calculate the angle it will pour. I can use it to deactivate the pour object when it’s not at the right pour angle.
I added a little update to containerIngredients to calculate the total current volume held and a log, as well as a stop to adding when at capacity:
And the cup is filling, now I need to get to removing the liquid from the jug. I may need to rejig some stuff with the raycasting cylinder. Ideally the DispenseIngredient should be on the Jug and the Jug should produce the raycasting cylinder. I ended up using events because it made more sense in my brain to use it that way - The dispensing is done by the jug and the pouring cylinder should be doing the raycasting and then calling whatever is subscribed to the DispenseTo event on this script. Thanks Mike for the help 😄
It’s now removing the right amount from the jug as it goes into the cup. No spilling yet!
Next step is for me to add the tilt angle to turn the pouring on//off. It’a late again here so I’ll finish here for today. 🛏️















