Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Architecte

Hello,

I would like to determine the direction for a bot.
Among the four movements of the bot (up, down, left, right) with the collision system I can not know if it is possible to know the only way possible when the other 3 are blocked, except for one test one hand the solutions, but in this case we see the character test each solution (ie switch positions).
Is there a way to simulate the worst travel before the bot to do for the right to take the right solution?

Thank you in advance

1 decade ago by vincentpiel

So if i understood well you would like to know about the possibles
collision that would affect your bot before it moves, so that you can
choose next bot move within the 'free' directions : the directions with
no collision.

For the static collision (collision bot <--> map ), you could do some
checks by just looking at the tiles around : Map.getTile is here.
http://impactjs.com/documentation/class-reference/map#gettile
or you might need more precision and have to use CollisionMap.trace :
http://impactjs.com/documentation/class-reference/collisionmap#trace

For the dynamic collisions, things are a more complicated since :
* the entities have different types and collision mode.
* they move

Just to give the start of a solution :
get within an array all entities that are :
1) 'not to far'
2) right type
3) right collision mode.
then test collisions against the bot and those selected entities.

Here just a fast idea of what the 'willTouch' function could look like :

(copied from Entity.touches)
willTouch: function( other, direction, distance ) {
           var xDelta = 0, yDelta=0;
           if (direction == 'N') yDelta=   distance;
           if (direction == 'S') yDelta= - distance;
           if (direction == 'E') xDelta=   distance;
           if (direction == 'W') xDelta= - distance; 		
		return !(
			this.pos.x + xDelta >= other.pos.x + other.size.x ||
			this.pos.x + xDelta + this.size.x <= other.pos.x ||
			this.pos.y + yDelta >= other.pos.y + other.size.y ||
			this.pos.y  + yDelta + this.size.y <= other.pos.y
		);
	}

Notice that it does not take into account the other speed, but you guess how to do so (other.pos.x + other.vel.x* ig.system.tick , ...)
Page 1 of 1
« first « previous next › last »