Code Monkey home page Code Monkey logo

angrybots_ecs's Introduction

AngryBots ECS

The DOTS project used for the presentation Converting Your Game to DOTS and contains an example of how DOTS could be used to replace a low performance process in your games (shooting many bullets at once, in this case). This is meant to provide a simple, targeted example. While it is true that there are other ways to optimize the game object version of this game, those same optimizations would apply to entities as well. As such, this represents a decent comparision of performance as well as example of how to do the conversion. A video presentation of this project can be seen here.

The basics

This project uses a combination of game objects and entities together. In this case, the player (game objets) spawns bullets (entity). There is an Enemy Spawner (game object) that spawns enemies (entities).

Collision

Since the bullets and enemies are entities and the player is a game object, making them collide with the built in physics system won't work. As such, collision is handled by a system (CollisionSystem) that is very simplistic in nature. In this system general radius is used to calculate if bullets have collided with enemies or enemies with players. A more sophisticted collision algorithm, or even the new DOTS physics, could have been used, but this is meant to be a simple example and this poorly optimized algorithm helps demonstrate the performance capabilities of burst compiled code.

The systems

Several systems are used to replace the monobehaviour functionality of the bullets and enemies

  • MoveForwardSystem - Moves any entity with the MoveForward component forward at some speed
  • TurnTowardsPlayerSystem - Turns enemy entities to face the player's position
  • CollisionSystem - Detects simple radius collision between bullets, enemies, and players
  • RemoveDeadSystem - Destroys any entities that have a Healt of zero or less
  • TimedDestroySystem - Destroys any entities that have run out of time to live (bullets)

Other Information

There are other interactions in the code that may not be apparent when you first look at it, so they are called out here

  • Bullet and Enemy prefabs are baked in the normal way (using a sub-scene and Authoring scripts) however enemy and bullet entities are spawned in the EnemySpawner and PlayerShooting monobehaviours (respectively)
  • The PlayerController monobehaviour creates an entity to store the player's health and position. This is so the CollisionSystem can easily check for collisions between enemies and the player, and adjust the player's health accordingly
  • The player's position is also stored in the Settings monobehaviour so the TurnTowardsPlayer system can access it. This is not normally something you should do, instead deciding on one way or the other. This project does both simply for demonstration purposes

angrybots_ecs's People

Contributors

mikegeig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angrybots_ecs's Issues

Typos / Readme.md

There are a few typos:

  1. line №5

“…In this case, the player (game objets)…” should be replaced with
“…In this case, the player (game objects)…”.

  1. line №15

“…entities that have a Healt…” should be replaced with
“…entities that have a Health…”

  1. line №17

“…this sytem is needed…” should be replaced with
“…this system is needed…”.

Request update to 2019.3

When I upgrade the project to 2019.3, I get many errors and I don't know how to fix them. Could you update the project to 2019.3?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.