Obstacles / The entity front end

Published June 28, 2009
Advertisement

Obstacles


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.
Previous Entry Flocking behavior
Next Entry Life is good.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement