Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Obstacles / The entity front end

Sign in to follow this  
Staffan E



Now handling of the inter-collisions between enemies is up and running, through an Obstacle component. It shares position, velocity and mass data with the Vehicle component. The data sharing within entities seems to be working perfectly which makes me very happy. Right now the collisions use circle-circle tests and the response uses an incorrect physical model with no momentum distribution between bodies. I will fix this soon. Another flaw is that the enemies always face in the direction of travel, so when they collide they spin around to face away from each other which looks strange. I'll have to separate facing direction and travel direction in some way.

The entity front end

The front end of this system is up to par with my expectations. For the current enemy swarm the creation code looks like this.

for ( int i = 0; i < 10; i++ ) {
unsigned int id = entityManager.createEntity( );
entityManager.addVehicle( id, ENEMY_MAX_FORCE, ENEMY_SPEED, 1000 );
entityManager.setValue( id, "posx", rand_linear( -500.0f, 500.0f ));
entityManager.setValue( id, "posy", rand_linear( -300.0f, 300.0f ));
entityManager.setValue( id, "velx", 0 );
entityManager.setValue( id, "vely", 0 );
entityManager.setValue( id, "mass", ENEMY_MASS );
entityManager.addSeekBehavior( id );
entityManager.addSeparationBehavior( id, 100 );
entityManager.addCohesionBehavior( id, 100 );
entityManager.addAlignmentBehavior( id, 100 );
entityManager.addVideo( id, "Target", 0.5 );
entityManager.addObstacle( id, ENEMY_RADIUS );

Here every iteration creates an entity, getting its id. The id is then used to add vehicle, video and obstacle components (the two latter at the end). Some setup parameters are supplied to each component, like max force, speed, "Target" sprite id and scale, and radius for the collision. The setValue() method sets a shared value for the given entity. I decided not to set these values in the add[component] methods because I wanted the final result to be independent of the order of adding components. If the adding a vehicle sets position to one value and adding an obstacle sets it to another, the order of adding would matter. Also the four behaviors for the vehicle are added. If there was no vehicle component these methods would throw. This is typical code that could be moved to a script with access to the entity manager.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 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!