Marble State Machine



Marble States Intro
Each Marble have three states: "Base", "Boost", and "Conserve". Different physic materials are assigned to different states.
Base State
- Medium friction and bounciness
Boost State
- Low friction and high bounciness (very unstable)
- A force is added to the marble to speed it up along the track
- Five acceleration gates are assigned along the track. Each time when a marble get through the gate, it will enter boost state for 1 second.
Conserve State
- High friction and low bounciness (slow but stable)
Other Marble Attributes
Health
- Value ranges between 0 and 100.
- In Base and Boost state, the marble health will decrease on each collision, in proportion to the velocity during the collision.
- In Conserve state, collision won't affect the health. Meanwhile, the health will recover in proportion to the time.
Turbo
- The number of times that a marble can enter Boost state, except entering acceleration gates.
- The max number of Turbo is 10.
- When turbo is activated, the marble will enter Boost state for 1 sec, and then will have 10 sec cooling down (turbo could not be activated when cooling down).
- Turbo can only be activated if the marble is in Base state.
- Turbo activation rule 1: when the marble velocity is below 2.5, the turbo could be activated.
- Turbo activation rule 2: if any rival marble is within 5 checkpoints, there are 0.5 chance during each update, that the marble will activate turbo to overtake.
- On each collision, the turbo value will increase a little, in proportion to the velocity during the collision. However, the turbo value won't increase if the marble is in Conserve state.
Switch Between Marble States
Entering and Exiting Boost State:
- If a marble goes through an acceleration gate, and the marble state is Base or Conserve, the marble will enter boost state.
- When a marble activates turbo (based on the Turbo rules mentioned above), the marble will enter boost state.
- Boost state has a time limit (usually 1 sec). The marble will fall back to Base state when the time is up.
Entering and Exiting Conserve State:
- The marble will enter the Conserve state if its health is below 10.
- The marble will exit Conserve state if health is higher than 80,
- A marble may also exit Conserve state and enter Boost state (as mentioned above) if it goes through an accelerate gate, even if the health is lower than 80.
Technical Challenge: How To Set the Boost Direction?
A seemingly simple question: letting the marble know the correct track direction, is actually quite challenging.
The most straight forward way is setting checkpoints along the track to set the direction. However, I'm not that interested in manually doing so.
In my case, most part of the track has a downward slope. Thus, I used ray casting to calculate the gradient of the track where the marble is at. Then, the reverse direction of the gradient is the correct direction. Then only exceptional part is a "lift" at the end of each lap. I just simply set a trigger there, and manually set the force direction that could push the marbles up the slope.
Get Simulation Project 2 Smart Marble Race
Simulation Project 2 Smart Marble Race
Status | Prototype |
Author | ricercarg |
Genre | Simulation |
More posts
- Race Manager and UI4 days ago
- Track Design & Shader13 days ago
Leave a comment
Log in with itch.io to leave a comment.