Advertisement

How handle Player Character behaviour with Lots of functionality

Started by July 16, 2021 09:42 AM
1 comment, last by Shaarigan 3 years, 5 months ago

hi.

I'm working on a player character behavior that has lots of behaviors like (wall-ladder) climbing, shooting, melee, charging and …

my base approach is using a state machine like inAir, Grounded, OnWall.

my character is a sensory system and input-handler that is general and calculated at each frame. in this sensory system, I decide that my player character should be in which state and which inputs and logic should be used in that state.

I assume it should work fine but I think I will have a sloppy code if the gameplay and behaviors get bigger.

I think techniques that are used in managing AI codes like BT and Goap can also be used to make a batter-managed code in a big behavior code base.

do you know a better approach for managing a character with lots of behaviors?

What I did when I was told to write a prototype for a farming game was to decouple the behavior from the character completely. This means that instead of the character controlling the interactions, an object in the world will give the character the option to interact with it.

I don't know how your game works but you'll already have a technique to determine when a character is on a ladder for example. Use that to “enable” the character to climb up the wall for as long as the ladder is in reach. We build everything up this principle, from opening doors to cropping without any great impact on the development process.

If you have interactions which don't require an object as ‘partnered’, you can handle this on a couple of possible ways. Your State Machine approach is great for such interactions as states define the interactions which can be chained onto the current one. The second option I could think about is via handling the interaction through the input system. If the input was handled and action was released, you simply flag the input as handled and skip every other interaction controller.

Last but not least, you may want to have a look at the Reactive Programming Pattern. It can be implemented in different languages and acts as a stream of event data which controller can subscribe to and unsubscribe from if needed. C# for example also provides some LINQ like functions which allow to filter subscriptions, for example if you listen to certain state of an event

This topic is closed to new replies.

Advertisement