Jump to content
  • Advertisement
Sign in to follow this  
Tristan Patrick Richter

Physics inside ECS Architecture or Separate Physics Engine?

This topic is 585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Do not put your physics in your ECS.

Game object architectures are part of the game logic framework.

Your ECS isn't going to be a good data structure for your physics. Nor is it going to be the best data structure for rendering. Nor for AI. Even if you intimately tie your engine modules and your ECS together you're still going to have to end up creating separate data structures and glue code anyway to do efficient ray casts, frustrum culling, path finding, etc.

Build your main modules to be as independent as possible. Make them testable and usable on their own, depending on no more than your core code like allocators or containers. Then use the object architecture to do glue objects together and to handle your level serialization, prefabs, UI integration, etc. Build your actual game logic over that glue layer.

Heck, if you build an _actual_ ECS then the "gluing" is basically free and almost implicit, in the simpler cases at least (since the "E" in an ECS is just an integer, all it would require is that your physics module support fast O(1) lookup and retrieval of an integer associated with each body).

Share this post


Link to post
Share on other sites

Don't both of your options count as making a physics engine, just that one uses the ECS pattern for the engine, and the other glues the end result into the ECS pattern?

 

You could always use PhysX / Bullet / Newton / etc instead of reinventing the wheel. Writing a physics engine is an extremely huge and complex task requiring a hell of a lot of research (depending on requirements / quality desired).

 

What is the purpose of your ECS framework? Is it so that non-programmers can construct new entities from data files, or so gameplay effects can dynamically tag entities with modifier-components, or because you like relational design theory in general? There's a lot of ways to do ECS, which completely depends on what your purpose is.

Share this post


Link to post
Share on other sites

Yes and no. That works for some checks. But it's possible to check for collisions without using a full physics engine, too.

Share this post


Link to post
Share on other sites

I think, think of your ECS as proxy to your modules. The components take the data (in this case, related to physics, in a way your artists/game designers could understand) and then the data is processed by whichever module through the related systems. This makes it easier to attach any 3rd party library. In this case, your physics module/library/engine/whatever. Just a quick thought.

Share this post


Link to post
Share on other sites
Physics engines are usually both collision detection and resolution. Resolution involves the difficult mathematics. If you want really simple resolution, then I'm sure you could figure out a way to get colliders into your ECS. So yeah, you can, but whenever someone comes in here to write a response we aren't thinking about "can you", but instead are thinking about "should you". Then answer to should you, is probably a no.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!