0

I am developing a game using GameplayKit, built on Entity Component Framework, and utilising GKStates.

I would like to know what is the best practice for the following:

I have a game entity, called Person. This person wanders the scene doing their own business. They are in WANDER GKState. If they bump into another person, they start chatting for example, or fighting...

My question is, where should I put the contact physics code? Should it be in the Person's OnContactBegin method or should it be placed in the WANDER GKState, inheriting a physics component that supports OnContact methods?

Either way works, but what is the cleanest or preferred method? Currently, the code is all in the Person entity but as more behaviours are add, the OnContact method is getting bigger and unruly and I'm beginning to think I should put the code in the various GKStates.

Any suggestions?

Jason
  • 1

1 Answers1

0

Actually GKStateMachine it's classical Finite-state machine. So the best way is to switch the state machine to the appropriate state through an external event.

Max Gribov
  • 388
  • 2
  • 7
  • So I understand this statement to mean that within my class Person's OnContact method, I should check for various states, e.g. am I touching another Person, move to Chat state? Or I am already in Chat state and still touching another Person, move to fight state. Might be time for diagrams... – Jason Jul 18 '18 at 10:55
  • I don't know what kind of logic you want to implement. But usually the switch of states occurs as a result of events. For example, the game unit was in state " go forward", then faced with an obstacle - which was an event that switched to the state "turn right" ... etc. – Max Gribov Jul 24 '18 at 09:50
  • I've decided not to have physics body contact checks within my states because I read somewhere that computational resource allocation is reduced and limited within state machines, probably because of what you said above. – Jason Jul 25 '18 at 13:37