-
Notifications
You must be signed in to change notification settings - Fork 0
Machine Scripts
There are numerous scripts for the machines, they all work under the same format just with some changes depending on the functionality of the machine.
These scripts are:
- Machine Manager
- Packaging Machine Manager
- Heating Machine Manager
- Funnel Counter
The base idea of the machine manager script is to use trigger objects to detect when an object enters the machine using the OnTriggerStay() function. When this happens, the machine will if enough time has passed for another bottle to be accepted and if the storage size is not full. If this passes, it then deletes the entered game object and adds it's entered time to a queue. Through the update() function, the script will then check if enough time has passed for the top object on the queue to be released, in which case it will remove the time from the queue and spawn the processed object. It is important to note that this object keeps track of its own timer and updates this timer itself using the timeController object to ensure that the bottles will come out relative to speed increases.
Additionally, this script controls defect production for each machine. This defect chance is calculated each time a product is about to leave the machine using the CalulateDefectChance() method - if a defect is created, the defective product will drop into the defect collector bin instead of continuing along the conveyor line, and that product will have been lost. When machine speeds are raised, the chances that a defect will be produced become higher. The chances max out at 50%, however, this should not be reached unless the machines were to be set to ridiculous speeds. Defects spawn around the coordinates set in the vector defectSpawnLocation after being slightly randomized by the RandomizeDefectSpawn() method for visual effect (this is currently configured so that all defects land in the defectCollector box beneath the Grille object on each machine). Defect production can be toggled on and off using the generateDefects boolean included in this script.
The packaging and heating managers are children of the machine manager class.
The packaging machine manager is made to handle taking in different counts of bottles and outputting different size packages depending on what is currently selected by the user. The user can click buttons which will activate the switchSix() to switchTwentyFour() functions to change this setting.
The heating machine manager is made to handle taking in different types of objects and outputting the same object but as a heated variant. As such it uses two parallel queues to keep track of both the input times and input type of the object. Then when it gets released from the machine it releases the correct type of the heated package.
The packages handled by the heating and packaging machine managers have a slightly higher chance than an individual bottle to generate a defect, since they handle up to 48 bottles at a time, but the curve is much gentler than "since each bottle has a 5% base defect chance, a 48 bottle package has a 5% * 48 chance to be defective". The curve does scale slightly as packages get larger. The CalculateDefectChance() method still handles all of these calculations, as in the case of the regular machine manager.
While the funnel counter is not a machine manager, I felt it important to keep this here as it directly works with the first machine manager. The funnel counter takes will get a number of bottles added to it by the forklifts through the order manager script. When it receives bottles, it will attempt to add bottles directly to the first machine manager. The bottles that are created and go up the conveyor are purely aesthetic. When the funnel tries to add bottles to the machine, the machine will either reject or accept the bottle, and it will do the same process as described above.
There are also scripts that are used for managing the speeds of these machines which are:
- Machine Speed Controller
- Packaging Machine Speed Controller
- Heating Machine Speed Controller
- Machine Spawn Control
These scripts are used to translate the speed of the player selection to the speed of the machine managers. When the user presses buttons on the object to increase or decrease the speed it will call functions within the connected scripts such as increaseSpeed(), decreaseSpeed(), and stopStart(). It will use the changeSpeedText() function when the user updates the speed using the text input. The user will be seeing the speed on their end as an object Per Minute value. The machine managers use a timeToProcess value in number of seconds. Therefore, this script will also convert between these two values as needed.
The Machine Spawn Control script is different as it handles both the speed of the first Machine Manager and the speed of the funnel Counter at the same time. It ensures that the funnel counter attempts to release bottles at the same speed as the machine manager can accept them. Otherwise, it is almost exactly the same as the other scripts.
- Current Branch Descriptions
- Version 1 Game Flow Overview
- Version 2 Game Flow Overview
- Localization and Start Screen Canvas Organization
- Overview of Scripts and Connections
- Machine Scripts
- Order Releases
- Demand
- Stage Controller
- Data Collection
- Video Recording
- Money Tracking
- Quest Systems for Levels and Tutorials
- Object Pooling
- Time Controller
- Forklift Scripts
- OpenAI Assistant Integration
- Ray Casting
- Camera Script
- General Purpose Object Collision