0
\$\begingroup\$

Some background on my engine, each system stores a reference to an entity which has the relevant components for that system. For example movement system has only entities which possess position components, render system takes positions and textures etc.

I'm working on an Entity-Component-System Game Engine for a project and I've hit a bit of a brick-wall in regards to how I'm going to handle input for the entities. I'm unsure of how I would translate say a "W" press input into the movement of a single entity(the player)? I don't want to move the entity inside the input system. I'm unsure of how to go about taking input and getting it to result in a response.

This is my first question, if there's anyway I can improve it or if theres any additional information needed I'd be happy to oblige.

\$\endgroup\$
0
\$\begingroup\$

This is just a short answer, since many details of your engine are unknown to me.

You need to remember that your InputSystemshould not cause the movement directly, as it may be context dependent when you press 'W'. Are you in a menu and your button selection should move up, character should move forward and in a vehicle accelerate. Additionally, your InputSystem does not know about the surrounding. Is a wall infront of the player, is the player in the air etc.
What it should do is change the acceleration of the player or the object. It should write this in a component that both the InputSystemand the MovementSystemcan access, e. G. the MovementComponent.

The MovementSystemin this case is more like a PhysicsSystem. It reads in the MovementComponent that the entity wants to move in the 'W'-direction. It checks, if that is possible. Is there a wall? Is the player on the ground (or ice, conveyer belt etc.) and then calculates the new position. This is then written in the PositionComponent.

Of course the context of your input can be checked in another sytem than your InputSystem, like the system that sort of is the game, some GameruleSystem. In this case the InputSystem writes the command in the MovementComponent, GameruleSystemreads this and reads the context, then writes in the PhysicsComponentwhat should happen. Moving forward, moving upwards, jumping. This is dependent on the game type.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for the response! A lot of helpful knowledge in your response, I'm aware I probably left a lot out in terms of information on the engine, nonetheless you still helped. I'm fine with designing most of the system functions, but I think the part I'm struggling with most is keeping game code and game engine as seperate as possible. If you've got any advice/tips on that, I'd much appreciate it! \$\endgroup\$ – Yrrah98 May 18 '20 at 16:27
  • \$\begingroup\$ @Yrrah98 im not sure there is a clean cut to make. In theory, you could create everything in the engine and only have some scripts doing the controls (with a script language of course). I would suggest to write down, what your engine should do and implement as much as possible. And even when you are already creating a game, you can still change and add parts of your engine. \$\endgroup\$ – PSquall May 18 '20 at 17:24
  • \$\begingroup\$ You're right, I'm probably getting a little bit ahead of myself at the moment. This is my first attempt at working with ECS architecture and I think I'm trying to run before I can walk. I'm enjoying doing it though, its much nicer to code up than in a traditional engine. I was wondering, do you have any sources you would recommend for learning more about ECS? Thanks a bunch! \$\endgroup\$ – Yrrah98 May 18 '20 at 18:09
  • \$\begingroup\$ @Yrrah98 just search for it hin Stack Exchange, you will get a lot of good examples and questions. I also like gameprogrammingpatterns.com, good and easy to understand. And you can access the web-version for free. Look for the chapter "components".and "data locality" \$\endgroup\$ – PSquall May 19 '20 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.