Expanding on the State Machine

So currently, you'll notice that in the Idle state we are setting our velocity to 0,0 every single frame. In this simple example, it's not a terribly big deal, but this overdoing of calculations is something that we'd like to avoid in the future. We only really need to do it once, right when we enter the state. We may also want to do certain actions when we leave the state, but we won't be able to do that in the current form of our State Machine, so we are going to need to redo some stuff.

First, let's go back to the ChasePlayerComponent.h file and add the following bold function definitions:

class ChasePlayerComponent : public M5Component { public:   ChasePlayerComponent(void);  virtual void Update(float dt); ...

Get Game Development Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.