<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged finitestatemachine</title>
<link>https://coderlegion.com/tag/finitestatemachine</link>
<description>Powered by Question2Answer</description>
<item>
<title>The Quick Brown Fox 2: The Silent Hordes</title>
<link>https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes</link>
<description>&lt;h2 id=&quot;the-quick-brown-fox-2-the-silent-hordes&quot;&gt;The Quick Brown Fox 2: The Silent Hordes&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Implementing High-Performance AI at Scale with FSM_API&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In our &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/6261/learn-how-fsmapi-uses-decoupled-state-machines-to-run-a-fox-and-dog-ai-simulation&quot;&gt;previous article&lt;/a&gt;, we introduced the &quot;Quick Brown Fox and Lazy Sleeping Dog&quot; demo. We showed how &lt;code&gt;FSM_API&lt;/code&gt; allows you to decouple agent data from behavior, creating a clean architecture where a Fox could detect a Dog, transition to a &quot;Jumping&quot; state, and (hopefully) land safely.&lt;/p&gt;
&lt;p&gt;It was a simple, controlled test. But &lt;code&gt;FSM_API&lt;/code&gt; isn't just for handling one fox and one dog. It is built for the Singularity.&lt;/p&gt;
&lt;p&gt;So, we asked a harder question: &lt;strong&gt;What happens when 66,000 agents try to coexist in a rapidly expanding universe?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To answer this, we built &lt;strong&gt;&quot;The Gauntlet.&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-setup-a-dynamic-stress-test&quot;&gt;The Setup: A Dynamic Stress Test&lt;/h3&gt;
&lt;p&gt;We took the exact same FSM definitions from our simple demo—&lt;strong&gt;Walking, Jumping, Sleeping, Chasing&lt;/strong&gt;—and dropped them into a stress-test environment designed to break them.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The World:&lt;/strong&gt; An infinitely expanding 1D grid that grows automatically to accommodate population density.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Agents:&lt;/strong&gt; Thousands of &quot;Foxes&quot; traversing the grid and thousands of &quot;Sleeping Dogs&quot; acting as dynamic landmines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Logic:&lt;/strong&gt; We implemented &lt;strong&gt;Spatial Hashing&lt;/strong&gt; to allow agents to query their neighbors efficiently. Foxes look ahead; if they see a dog, they jump. If they land on a dog, it wakes up. If a dog wakes up, it chases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This isn't just a benchmark of raw loops; it is a benchmark of &lt;strong&gt;state integrity&lt;/strong&gt;. Every single agent is a fully independent FSM Context running its own logic cycle.&lt;/p&gt;
&lt;h3 id=&quot;the-results-the-tip-of-the-iceberg-&quot;&gt;The Results: The &quot;Tip of the Iceberg&quot;&lt;/h3&gt;
&lt;p&gt;We ran the simulation until the framework hit the limits of a standard development machine (maintaining \~30 FPS). The final snapshot tells a brutal story:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Metric &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Count &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Context&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Total Agents &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;66,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;A population larger than many real-world towns.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Dogs (Hazards) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;19,711 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Nearly 20,000 active threats monitoring the field.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Foxes (Dead) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27,362 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Casualties of &quot;bad luck&quot; RNG (landing on a dog).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Foxes (Alive) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;18,927 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The survivors pioneering the edge of the world.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;the-silent-stress-test&quot;&gt;The &quot;Silent&quot; Stress Test&lt;/h3&gt;
&lt;p&gt;While the death count is tragic (RIP to the 27,362 foxes who failed their jump checks), the most shocking metric wasn't the carnage—it was the &lt;strong&gt;activity level&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;At peak load, with nearly &lt;strong&gt;20,000 dogs&lt;/strong&gt; monitoring the field, &lt;strong&gt;only 2 were awake.&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;why-this-matters-for-performance&quot;&gt;Why This Matters for Performance&lt;/h4&gt;
&lt;p&gt;This &quot;boring&quot; stat is the ultimate proof of the &lt;code&gt;FSM_API&lt;/code&gt;'s architecture. In a naive implementation, checking 20,000 AI agents for targets usually kills the CPU. But here, the simulation remained playable at 30 FPS because the FSMs efficiently handled the &quot;Idle Load.&quot;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The Hidden Workload: Every single frame, &lt;strong&gt;38,000+ alive agents&lt;/strong&gt;&lt;br&gt;
are evaluating their Transition Conditions.&lt;ul&gt;
&lt;li&gt;Dogs: &quot;Is anything touching me?&quot;&lt;/li&gt;
&lt;li&gt;Foxes: &quot;Is there a dog in the next cell?&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ol&gt;
&lt;li&gt;Live Action Metrics:      &lt;ul&gt;
&lt;li&gt;Active Chases: ~2 to 12 dogs awake at any moment.&lt;/li&gt;
&lt;li&gt;Fleeing Foxes: ~1 to 5 foxes sprinting for their lives.&lt;/li&gt;
&lt;li&gt;Jumps per Frame: ~600 foxes airborne right now.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This creates a self-balancing ecosystem. The API is maintaining the memory and state integrity of &lt;strong&gt;66,000 objects&lt;/strong&gt; simultaneously, but because the &lt;strong&gt;&quot;Sleeping&quot;&lt;/strong&gt; state logic is lightweight, the system can handle thousands of them for free. However, the system retains the &lt;strong&gt;Burst Potential&lt;/strong&gt; to handle chaos: if a swarm of Foxes lands on a pack of Dogs, those Dogs will wake up, transition to &quot;Chasing,&quot; and execute complex logic instantly.&lt;/p&gt;
&lt;h3 id=&quot;from-hello-world-to-production-scale-&quot;&gt;From &quot;Hello World&quot; to &quot;Production Scale&quot;&lt;/h3&gt;
&lt;p&gt;We went from a simple demo with one fox to managing &lt;strong&gt;66,000 active, logic-driven entities&lt;/strong&gt; without changing the core FSM definitions.&lt;/p&gt;
&lt;p&gt;We aren't just simulating the &quot;action movie&quot; moments of chases and jumps; we are simulating the &lt;strong&gt;quiet complexity of a living world&lt;/strong&gt;. The fact that 19,000 dogs can sleep efficiently while monitoring their surroundings proves that the &lt;strong&gt;FSM_API&lt;/strong&gt; is ready for scale.&lt;/p&gt;
&lt;h4 id=&quot;what-s-next-&quot;&gt;What's Next?&lt;/h4&gt;
&lt;p&gt;We are currently hitting a ceiling around 70,000 agents due to the overhead of string-based state lookups (e.g., checking CurrentState == &quot;Sleeping&quot; thousands of times per frame).&lt;/p&gt;
&lt;p&gt;In our next update, we are refactoring the backend to use Integer Hashing. Our early benchmarks suggest this could increase throughput by an order of magnitude.&lt;/p&gt;
&lt;p&gt;But we won't stop there. Once we have optimized the micro-operations, we will be &quot;Going Wide&quot;—exploring how to leverage FSM Processing Groups to run massive, parallel simulations across multiple cores.&lt;/p&gt;
&lt;p&gt;Stay tuned. The Singularity is getting closer.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Simple Demos Repository (Run the Stress Test): &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17381643093345870659&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes</guid>
<pubDate>Mon, 01 Dec 2025 04:19:58 +0000</pubDate>
</item>
<item>
<title>10. FSM_API for Non-Coders: A Big Picture Overview (From our Documentation)</title>
<link>https://coderlegion.com/7412/10-fsmapi-for-non-coders-a-big-picture-overview-from-our-documentation</link>
<description>&lt;p&gt;We believe the most reliable software logic is logic everyone can understand.&lt;/p&gt;
&lt;p&gt;The complex systems that drive modern applications—from character AI in games to business workflows and industrial robotics—are often best articulated not by a developer, but by the subject matter experts. These experts instinctively express domain behavior as an organized set of phases and rules, often visualized as hierarchical Finite State Machines.&lt;/p&gt;
&lt;p&gt;This natural structure is the foundation of the Finite State Machine (FSM), and it is why we created this overview. FSMs are not merely a developer’s tool; they are a universal language. This guide is designed to bridge the gap, enabling your domain expertise to translate seamlessly and reliably into the design of robust, predictable, and maintainable software systems.&lt;/p&gt;
&lt;p&gt;Without any further ado:&lt;/p&gt;
&lt;h2 id=&quot;10-fsm-api-for-non-coders-a-big-picture-overview&quot;&gt;10. FSM_API for Non-Coders: A Big Picture Overview&lt;/h2&gt;
&lt;p&gt; Have you ever tried to describe a complex process to someone, like making coffee ☕ or building a LEGO castle , and found yourself saying, &quot;First you do this, &lt;em&gt;then&lt;/em&gt; if that happens, you do this other thing, &lt;em&gt;otherwise&lt;/em&gt; you do something else entirely&quot;? If so, you've already grasped the core idea behind &lt;strong&gt;Finite State Machines (FSMs)&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;At its heart, FSM_API is a powerful tool designed to make complex software behaviors predictable, organized, and easier to manage, even if you don't write code yourself. It helps turn messy, &quot;if-this-then-that&quot; logic into clear, step-by-step instructions.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-is-a-finite-state-machine-fsm-the-simple-version-&quot;&gt;What is a Finite State Machine (FSM)? (The Simple Version)&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/TrafficLightFSM.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/TrafficLightFSM.png&quot; alt=&quot;A state machine diagram of a traffic light.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;A simple, real-world example of an FSM: a traffic light.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Imagine anything that changes its behavior based on its current situation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;traffic light&lt;/strong&gt; is either Red, Yellow, or Green. It can't be Red and Green at the same time. It changes from Green to Yellow only, not directly to Red.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;door&lt;/strong&gt; is either Closed, Opening, Open, or Closing.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;game character&lt;/strong&gt; might be Idle, Walking, Running, Jumping, or Attacking.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An FSM is just a way to formally describe these behaviors:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;States:&lt;/strong&gt; These are the specific &quot;situations&quot; or &quot;modes&quot; an entity can be in at any given moment (like &quot;Green&quot; for a traffic light, or &quot;Walking&quot; for a character). An FSM is always in &lt;strong&gt;exactly one state&lt;/strong&gt; at a time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transitions:&lt;/strong&gt; These are the &lt;strong&gt;rules&lt;/strong&gt; that dictate how an entity moves from one state to another (e.g., from &quot;Green&quot; to &quot;Yellow&quot; when a timer runs out, or from &quot;Walking&quot; to &quot;Jumping&quot; when the player presses the jump button).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;FSM_API helps developers build and manage these FSMs in a clear and organized way, making sure all the rules are followed and behaviors are predictable.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;how-fsm-api-helps-you-even-if-you-don-t-code-&quot;&gt;How FSM_API Helps You (Even if You Don't Code)&lt;/h3&gt;
&lt;p&gt;While FSM_API is a coding tool, its benefits directly impact anyone involved in designing or understanding the behavior of a system, like game designers, project managers, or QA testers.&lt;/p&gt;
&lt;h4 id=&quot;1-clearer-communication&quot;&gt;1. &lt;strong&gt;Clearer Communication&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/Character_AI_FSM.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/Character_AI_FSM.png&quot; alt=&quot;A flowchart of an enemy AI, showing states like Patrolling and Chasing.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An FSM diagram like this gives the whole team a clear map of how the AI should behave.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Instead of ambiguous descriptions, an FSM provides a visual and logical map of how something behaves. Everyone on the team can look at an FSM diagram and immediately understand the flow.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; &quot;The enemy moves from 'Patrolling' to 'Chasing' when it 'sees' the player.&quot; This becomes a clear transition rule.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-fewer-bugs-amp-more-reliable-behavior&quot;&gt;2. &lt;strong&gt;Fewer Bugs &amp;amp; More Reliable Behavior&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;When behaviors are explicitly defined, it's much harder for unexpected &quot;edge cases&quot; or illogical situations to occur (like a character trying to jump while they are already dead). This leads to more stable and reliable software.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; Less time spent fixing frustrating, unpredictable issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-easier-to-change-and-expand&quot;&gt;3. &lt;strong&gt;Easier to Change and Expand&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Because the behavior is modular (broken into states and transitions), adding new features or changing existing ones becomes much simpler. You don't have to overhaul the entire system.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; Want to add a &quot;Stealth&quot; state to your enemy? You simply add the new state and define how to get into and out of it, without breaking the existing &quot;Patrol&quot; or &quot;Chase&quot; logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;4-better-performance&quot;&gt;4. &lt;strong&gt;Better Performance&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;FSM_API is built to be fast. This means your games or applications will run smoother, even when managing many complex characters or systems at once.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; A more responsive and enjoyable experience for the end-user.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;5-empowers-non-coders-the-context-connection-&quot;&gt;5. &lt;strong&gt;Empowers Non-Coders (The &quot;Context&quot; Connection)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/FSM_Context_Relationship.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/FSM_Context_Relationship.png&quot; alt=&quot;A diagram showing the FSM as a brain controlling the game object as a body.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The FSM (the brain) contains the logic, while the Context (the body) is the actual object that performs the actions.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When a developer uses FSM_API, they link the FSM to an actual &quot;thing&quot; in your game or application (this &quot;thing&quot; is called the &lt;strong&gt;Context&lt;/strong&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; A game designer might say, &quot;When the character is in the 'Jumping' state, I want them to play the 'Jump_Anim' and add an upward force.&quot; The developer then connects the FSM's &quot;Jumping&quot; state to the &lt;strong&gt;character's script&lt;/strong&gt; (their Context) which knows how to play animations and apply force.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; This clear connection means designers can specify behavior in terms of game actions, and developers can implement it precisely, using the FSM as the bridge.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;who-is-this-for-&quot;&gt;Who is This For?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Game Designers:&lt;/strong&gt; Visualize and plan complex character AI, game mechanics, and UI flows with clarity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Project Managers:&lt;/strong&gt; Understand the scope and complexity of features related to dynamic behaviors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;QA Testers:&lt;/strong&gt; Clearly define and test expected behaviors in various scenarios.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Technical Writers:&lt;/strong&gt; Document system behaviors accurately and concisely.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;FSM_API provides a common language and structure that helps bridge the gap between design and implementation, leading to more robust, understandable, and maintainable applications. We are actively working on integrating this into &lt;strong&gt;AnyApp&lt;/strong&gt;, and also preparing it for submission to the &lt;strong&gt;Unity Asset Store&lt;/strong&gt; so developers everywhere can benefit!&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;want-to-learn-more-about-development-&quot;&gt;Want to Learn More About Development?&lt;/h3&gt;
&lt;p&gt;If you're interested in learning about the coding side of things from a clear, practical perspective, we highly recommend checking out &lt;strong&gt;Tim Corey&lt;/strong&gt;. He's widely recognized as a fantastic resource for software development, and you can find his insightful content, courses, and community on his platform, &lt;strong&gt;DevForge&lt;/strong&gt;, at &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.iamtimcorey.com/&quot;&gt;iamtimcorey.com&lt;/a&gt;. &lt;/p&gt;
&lt;h3 id=&quot;resources-amp-code-&quot;&gt;Resources &amp;amp; Code:&lt;/h3&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17272823008937591128&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/7412/10-fsmapi-for-non-coders-a-big-picture-overview-from-our-documentation</guid>
<pubDate>Sat, 15 Nov 2025 22:14:52 +0000</pubDate>
</item>
<item>
<title>Completing the Motion Trilogy: The Reusable TranslationFSM</title>
<link>https://coderlegion.com/6450/completing-the-motion-trilogy-the-reusable-translationfsm</link>
<description>&lt;h2 id=&quot;completing-the-motion-trilogy-the-reusable-translationfsm&quot;&gt;Completing the Motion Trilogy: The Reusable &lt;strong&gt;TranslationFSM&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;We've conquered Rotation and streamlined Scaling using our FSM Context Pattern. In this article, we tackle the final primitive motion—Translation (linear movement)—to complete our core motion trilogy.&lt;/p&gt;
&lt;p&gt;The biggest takeaway here is the demonstration of true &lt;strong&gt;architectural reuse&lt;/strong&gt;. We define a new Context class and a new FSM, but the logic flow remains 100% identical to the Rotation and Scaling demos.&lt;/p&gt;
&lt;h3 id=&quot;1-the-context-swapping-scale-for-position-parameters&quot;&gt;1. The Context: Swapping Scale for Position Parameters&lt;/h3&gt;
&lt;p&gt;We isolate the specific data required for linear position change into the &lt;code&gt;TranslationContext&lt;/code&gt; class.&lt;/p&gt;
&lt;p&gt;The primary conceptual difference from the Scale/Rotation demos lies in how boundaries are established: Translation must calculate its absolute boundaries relative to the object's &lt;strong&gt;starting local position&lt;/strong&gt; (&lt;code&gt;OriginalPosition&lt;/code&gt;). This ensures the oscillation is centered around the object's initial placement.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Previous Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Translation Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Purpose&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;ScaleSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MoveSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Linear speed of position change.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;ScaleAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MoveAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The axis (or axes) to apply the movement along.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;MaxScale / MinScale &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MaxPosition / MinPosition &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The absolute position bounds, calculated from &lt;code&gt;OriginalPosition&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;translationcontext-cs-absolute-boundary-calculation&quot;&gt;TranslationContext.cs: Absolute Boundary Calculation&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;TranslationContext&lt;/code&gt; calculates the precise &lt;code&gt;MaxPosition&lt;/code&gt; and &lt;code&gt;MinPosition&lt;/code&gt; by using the dot product to find the object's starting coordinate along the movement axis, and then adding/subtracting the desired displacement.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class TranslationContext : IStateContext
{
    // The new parameters that define linear movement
    public float MoveSpeed = 1.0f;
    public float MaxPosition = 5.0f;
    public float MinPosition = -5.0f;
    
    public Vector3 MoveAxis;
    public Vector3 OriginalPosition = Vector3.zero;

    // ... Constructor logic
    // 2. Calculate the absolute Max/Min boundaries:
    this.MaxPosition = initialCoord + maxPos;
    this.MinPosition = initialCoord + minPos;
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;2-the-fsm-definition-the-same-engine-new-states&quot;&gt;2. The FSM Definition: The Same Engine, New States&lt;/h3&gt;
&lt;p&gt;The Finite State Machine flow is identical to the Rotation and Scalar demos (Move $\rightarrow$ Max $\rightarrow$ Move Back $\rightarrow$ Min). The blueprint name is now &lt;code&gt;&quot;TranslationFSM&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Scalar FSM &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Translation FSM (Change)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingUp &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: MovingForward&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingDown &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: MovingBackward&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Apex &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MaxReached&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Root &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MinReached&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;the-core-logic-simple-vector-math-&quot;&gt;The Core Logic (Simple Vector Math)&lt;/h4&gt;
&lt;p&gt;The state updates are handled by direct vector math applied to &lt;code&gt;localPosition&lt;/code&gt; using &lt;code&gt;Time.deltaTime&lt;/code&gt; for smooth, framerate-independent movement.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// The OnUpdateMovingForward function within TranslationContext.cs
private void OnUpdateMovingForward(IStateContext context)
{
    if (context is TranslationContext tc)
    {
        // Add the movement vector based on speed and time
        tc.TransformHandle.localPosition += tc.MoveAxis * (tc.MoveSpeed * Time.deltaTime);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The transition predicates, &lt;code&gt;MaxReached&lt;/code&gt; and &lt;code&gt;MinReached&lt;/code&gt;, use the &lt;strong&gt;Dot Product&lt;/strong&gt; to extract the object's current coordinate along the axis, comparing it to the absolute &lt;code&gt;MaxPosition&lt;/code&gt;/&lt;code&gt;MinPosition&lt;/code&gt; boundary values calculated earlier.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;3-the-entry-point-final-proof-of-reusability&quot;&gt;3. The Entry Point: Final Proof of Reusability&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleTranslationDemo.cs&lt;/code&gt; handles the instantiation. We simply provide three different &lt;code&gt;MoveAxis&lt;/code&gt; vectors to three unique &lt;code&gt;TranslationContext&lt;/code&gt; instances, all utilizing the same &lt;code&gt;&quot;TranslationFSM&quot;&lt;/code&gt; definition.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private void OnEnterExecuting(IStateContext context)
{
    if (context is SimpleTranslationDemo std)
    {
        float moveSpeed = 1.0f;
        float maxDisplacement = 2.0f;
        float minDisplacement = -2.0f;
        
        // 1. X-axis: MoveAxis (1, 0, 0)
        TranslationContext xAxisContext = new TranslationContext(std.Xaxis, new Vector3(1, 0, 0), moveSpeed, maxDisplacement, minDisplacement);
        std.XaxisHandle = xAxisContext.Status; 

        // 2. Y-axis: MoveAxis (0, 1, 0)
        TranslationContext yAxisContext = new TranslationContext(std.Yaxis, new Vector3(0, 1, 0), moveSpeed, maxDisplacement, minDisplacement);
        std.YaxisHandle = yAxisContext.Status; 

        // 3. Z-axis: MoveAxis (0, 0, 1)
        TranslationContext zAxisContext = new TranslationContext(std.Zaxis, new Vector3(0, 0, 1), moveSpeed, maxDisplacement, minDisplacement);
        std.ZaxisHandle = zAxisContext.Status;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;Conclusion: Architectural Reusability Confirmed&lt;/p&gt;
&lt;p&gt;With the implementation of the TranslationFSM, we have successfully completed our core motion trilogy, elegantly managing Rotation, Scaling, and Translation using a single, unified architectural approach.&lt;/p&gt;
&lt;p&gt;The key takeaway is the profound level of architectural reuse we achieved. By isolating the unique data (the what) into the Context class and retaining the generic logic flow (the how) within the FSM blueprint, we were able to build three distinct motion systems with virtually identical FSM definitions. This pattern has proven its ability to handle different primitive operations—be it altering localRotation, localScale, or localPosition—simply by swapping out the specialized context. This kind of separation of concerns leads to robust, maintainable, and highly reusable code.&lt;/p&gt;
&lt;p&gt;The final proof of concept in SimpleTranslationDemo.cs, simultaneously orchestrating three separate translation contexts with one FSM blueprint, underscores the pattern's efficiency and flexibility.&lt;/p&gt;
&lt;p&gt;Up Next: The Grand Finale&lt;/p&gt;
&lt;p&gt;We've mastered the primitives. In the final article of this series, we'll connect the three systems—RotationFSM, ScalingFSM, and TranslationFSM—to a single object. Get ready for the Combined Motion Demo, where we'll show an object spinning, pulsing, and oscillating all at once, driven by multiple, independently managed FSM contexts. This is where the true power of this decoupled architecture shines! Keep an eye out for the final installment.&lt;/p&gt;
&lt;p&gt;See the demo in action:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/SWzuJKpXIRU&quot;&gt;YouTube Channel Video&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6430030048270798462&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6450/completing-the-motion-trilogy-the-reusable-translationfsm</guid>
<pubDate>Tue, 14 Oct 2025 22:23:29 +0000</pubDate>
</item>
</channel>
</rss>