-
Notifications
You must be signed in to change notification settings - Fork 183
Add state driven player controller using state chart addon #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Gave this a very quick look. I've noticed that the states/transitions themselves all seem to still be their base class. |
|
If you mean moving each state's code to a separate class, it's possible but it seems it isn't nessesary. You can find in this issue why this could even complicated things more. and each method has its signal: and states' code ordered based on their node's position in the scene tree too: I think code traversing is fast enough, you can select a state, open its signals and open its code by double clicking on one of its signal but if your question is more about separation of concerns, I haven't a strong opinion about it. |
Thanks for linking that issue and describing your approach.
This is probably my preferred approach as well. I'm fine with keeping more logic in one script, as long as it's human-readable. 😃 Open to hear other approaches/considerations etc. |
|
I refactored code by moving all states related codes to their regions, for example sittable functions and variables moved to sitting state region. |
Nice, yeah, the cleanup in this definitely helps.
@mrezai Depends on what behaviour / improvement you are aiming for with this PR? I think just having the same behavior and functionality as the old/main character controller is probably a good start - and good enough for me. For extra features I'd love to see some of the "interaction states" tracked in the state chart as well, so for example if the player is
I've used the current state of this PR to see if I can use the state signals with an animation tree to give the player character a shadow, and it worked pretty well: Cogito_PlayerAnimationShadows_2025-05-19.mp4 |
I think we could do things in this order:
Nice, I consider this as a sign of that we are on the right track and there is hope at least for a while, until we find a better approach later! |
|
Fully onboard with this approach.
Let's work on them in the new one in this PR.
Agree. I'm not 100% sure anymore what my approach was with these, but I think there were mainly for input control. There's two specific states or checks that are needed:
Any GUI scene usually will have its own input processing, but can/should check the player controller for a state to make sure they don't conflict or cause unwanted behaviour, so they will need to check for either these states or bools.
This would tie in to what I mentioned above: We could give the player states a flag that gives devs control over when and what the player can interact with while in certain states (for example: stopping the player from using a keypad while falling)
absolutely agree! |
|
Thank you for the comprehensive explanation. |
|
Changes in d69ce7c:
I want to separate states in airborne to these three states:
@Phazorknight what do you think? |
|
Great updates, thanks!
I think this makes total sense and seems intuitive. |
|
@Phazorknight AirControl and FreeFall states added, please review, thanks. |
@lordsologamedev Please create an issue - this repo is not the place to bring this up. @mrezai will try to review over the weekend, thanks! |
|
@mrezai I think this is pretty good. These two states seem to work as I'd imagine. Going back to having other scripts/objects check for certain player states: As a start to think about how to tackle this, I looked into when I mentioned GUI Handling:
The opening/closing input handling of the Pause menu and Inventory screen is actually processed in the cogito_player script. My idea would be to be the following - but it might be a bit convoluted. As you're more familiar with the state chart addon, let me know your thoughts.
|
|
I like this idea but before any implementation, I want check some features of statechart like guard and condition state, maybe we can implement it in a more idiomatic way. |
|
@Phazorknight the latest changes:
I'll work on statechart saving/loading. |
|
@mrezai Still looks pretty good!
amazing, didn't expect this to be added so quickly.
thanks for this! Works great, though I have to admit I'd implemented this differently.
Sounds good. A third thing to consider would be to disallow saving the game in certain states (to avoid enabling the player to save the game right before falling to their death). Of course if we simply disallow opening the menu, then players can't save either way - that should ideally make this a bit easier. |
433fa44 to
04d8d45
Compare
|
@Phazorknight I rebased this branch on main to include latest changes, you need to get it again.
I've added no_interaction_states that prevents all interaction in its states but didn't remove disable_interaction_in_air because for example in jumping state I want to interact with all interactables except keypad and it seems this is the simplest way to do it.
This needs more thinking! |
|
Ledge climbing added, it needs some polish later: 2025-07-24-1.mp4 |
|
Swimming added + some refactoring, still some refactoring and bug fixing needed. 2025-08-08.18-43-31.mp4 |
|
Thanks
You are right, it might be ready in two weeks but I think it would be a good idea if someone more familiar with statechart review current implementation, mostly to prevent wrong usage of the framework, and I hope @derkork could help us in this regard if he has time and interested in this project. |
Cogito Player State Driven: - Added an Animation Player and Animation Tree - Created a script that uses signals from the state chart to update player animations. - Early implementation
…ate for saving/loading.
- Collision layer of CogitoStaticInteractable(cogito_demo_hint) is set to 4(NonPhysicalInteractables) to prevent unwanted crouching or ledge climbing.
|
Hey, I was quite busy last week but looks like you've done a lot of work on this. Will take a look at this the next few days.
They are not from Mixamo. I'm using the same as the NPC animations, which are listed in the Cogito Credits and are CC0, so no need to remove.
Makes sense, shouldn't be too tricky to add. |
I added this in 9403e51 but there might be other changes required. |
|
Hey mrezai, If you could add a new push/commit so I could retry, that'd be great. Sorry for the inconvenience! |
|
This branch is rebased onto the main to be in sync with it and this is the reason of the merge conflicts. |
|
Thanks, was able to fix the branch issue on my end and I think I was able to pull the latest.
Might be interesting to look into this old PR that also had water implementation: #246 |
|
Thanks for feedback, I'll take a look as soon as I can. |
|
@Phazorknight first and second issues are fixed. |
…don: - Add in water floating feature to the CogitoObject and CogitoProjectile. - WaterArea extends FluidArea3D. - Rifle mass set to 3.5. - One CarrayableBox added to swimming test area.
|
I added godot-floatable-body to project and based on it, added some properties to CogitoObjects. 2025-09-10.mp4 |
|
Sorry for the long delay but I finally got some time to look after COGITO more. Swimming feels great and the floatable bodies seem to work very well too. Mid-air control feels so much better now as well. I assume you're pretty close with this being ready to merge? |
|
No worries at all! I think it might be better to release version 1.2 without merging this feature and after that I can rebase this onto the version 1.2 to be usable for brave early adopters! My reasons for the above suggestion:
IMO merging this branch and other breaking changes into new major version is better idea than merging it into version 1.2. |
…when player opens a drawer that cause a unwanted crouching.
|
@mrezai Yeah sounds good. Your reasoning makes sense to me.
Might try to make it version 1.3 first 😇
thanks for pointing this out! I hadn't seen this before and this seems like it'd be super useful for Cogito. Will take a look. |



This is an experimental implementation of a state driven player controller using state chart addon.
I don't know this approach is acceptable or not but IMO it seems promising.
I started from platformer example in state chart project.
I made some modification in the Cogito code to simplify testing. Some of these changes will be removed later.
List of changes:
CogitoPlayeris now an empty base class.CogitoPlayerDefaultis current implementation and derived fromCogitoPlayer.CogitoPlayerStateDrivenis a copy ofCogitoPlayerDefaultthat refactored and modified to work using state chart.COGITO_3_LobbyTestStateDrivenPlayer.tscnandCOGITO_4_LaboratoryTestStateDrivenPlayer.tscnare copy of current demo scenes that their player replaced byCogitoPlayerStateDriven.COGITO_3_LobbyTestStateDrivenPlayer.tscn.Implementation details:
