Comments (1)
Hi @Invertex, thanks for reaching out with your question.
I don't think what you've described is a bug. I've translated my understanding of your intention into the diagram below.
stateDiagram-v2
Idle: Idle
Movement: Movement (needsExitTime)
state Movement {
Walk
Dodge: Dodge <br> (needsExitTime)
[*] --> Walk
Dodge --> Walk: Animation is finished <br> (forced)
Walk --> Dodge: Dodge input
}
[*] --> Idle
Idle --> Movement: Any input
Movement --> Idle: No input
As far as I can tell, there are two distinct things that you want to happen:
-
When inside the
Movement
state, theDodge
animation should finish before transitioning to theWalk
state. That's why theDodge
state should haveneedsExitTime
set to true. Because it needs exit time, it also needs a way to exit. As the customonLogic
function (Dodging
) probably does not call theStateCanExit()
method internally, the state transition needs to be forced from the outside, i.e. the transition needsforceInstantly
to be true. -
When the root fsm wants to transition from
Movement
toIdle
, it should not transition instantly if it's still playing the Dodge animation, i.e. theDodge
state has not exited yet. Therefore theMovement
state (machine) also needs its ownneedsExitTime
property set to true. TheMovement
state machine will then only exit, when its currently active state does not need exit time (like theWalk
state) or when a state that does need exit time (like theDodge
state) exits.
The canExit
field lets the state machine instantly transition out of a state that needs exit time. It will not be continually checked. In your case it does not make sense, as the Dodge
state's needsExitTime
property was set to false.
Without knowing the details of your code, I've tried to outline a solution in the code snippet below. Let me know if this helps.
// The root fsm does not needExitTime
StateMachine fsm = new StateMachine();
// Idle should be able to exit immediately => does not needExitTime.
fsm.AddState("Idle", new State(onLogic: Idle));
// As the movement state needs to remain in the active state as long
// as the animation needs to play, it needsExitTime.
StateMachine movementFsm = new StateMachine(needsExitTime: true);
fsm.AddState("Movement", movementFsm);
fsm.AddTransition("Idle", "Movement", _ => isAnyMovementInput);
fsm.AddTransition("Movement", "Input", _ => !isAnyMovementInput);
// The movementFsm state machine should be able to leave at any time
// if it is in the Walk state => Walk does not need exit time.
movementFsm.AddState("Walk", new State(onLogic: Walk, canExit: _ => isDodgeAnimationFinished));
// But as the Dodge animation has to finish before the state machine should ...
// a) transition to Walk, the Dodge state needsExitTime
// OR:
// b) exit and transition to Idle, the Dodge state needsExitTime AND
// movementFsm needsExitTime.
movementFsm.AddState("Dodging", new State(onLogic: Dodging, needsExitTime: true));
// forceInstantly is required because the Dodge state needsExitTime and it
// won't exit itself (by calling movementFsm.StateCanExit()). That's why a
// transition has to be forced "from outside".
movementFsm.AddTransition(new Transition(
"Dodge",
"Walk",
_ => isDodgeAnimationFinished,
forceInstantly: true
));
// forceInstantly is not required here because Walk does not need exit time
movementFsm.AddTransition(new Transition(
"Walk",
"Dodge",
_ => isPlayerPerformingDodge
));
from unityhfsm.
Related Issues (20)
- Use enums instead of strings for states HOT 3
- Best way to handle FixedUpdate code (physics)? HOT 6
- Trigger transition from state to same state possible? HOT 1
- Feature request: onEnter and onExit on non-root StateMachines HOT 2
- feature request: OnActiveStateChanged event? HOT 2
- Feature request: add OnTransition callback to Transition class HOT 9
- Name of Test asmdef can conflict with project HOT 1
- StateMachine<T> and StateMachine needs a common StateMachine base type HOT 5
- How to return to the previous sub-state of a Hierarchical FSM? (2.0) HOT 1
- Is there a StateChanged changed event for when any transition occurs, even a sub-machine one? HOT 3
- Trigger/Action should use a separate type
- Documentation request: Explain what HybridStateMachine is
- Sample code can not compile in version 2.0 HOT 2
- Mention Support for Generic State Identifiers Higher Up in README HOT 1
- How to visualize multi-layer state machines HOT 1
- How to use AddTransition in two different TStateId based by enum? HOT 1
- [Question] Any node editor for UnityHfsm?Or other Editor Tool ? HOT 1
- [Question] Support for parallel states HOT 2
- Perform logic in FixedUpdate or LateUpdate?
- More Samples/Explaination On Class-based architecture HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unityhfsm.