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

1 decade ago by wdvretuow

Hi there,

I was wondering how I could limit the movement of my enemy entity. My level is flat, there are no platforms or something so the enemy walks between the far left and right borders of the map.

I would like the entity to crawl sideways on 5 or 6 tiles. That's about it!

1 decade ago by wands

Not sure what you mean though. Any more details about what you're trying to do?

1 decade ago by wdvretuow

Let me clear it up again:

The basic crawl animation for my Enemy entity is that he walks left and right to the edges of the map, and when he bumps into the far left or right wall, he turns around and walks the other way. I want to limit those walls, so set up to invisible boundaries for the characters to walk between.

It has to be invisible so the main player won't bump into the wall.

So just to be clear: the Enemy entity has to stay in a certain place of 6 tiles and walk between them.

1 decade ago by dungeonmaster

As always there are different solutions to your problem.

Easiest is to hard-code it in to the enemyEntity's update. Check the .pos.x of the entity and if it reaches any of the limits simply make this.vel.x*=-1;

If you want more flexibility i.e. ability to put the limits in the Weltmeister, I can suggest two options:
1) Make an invisible entity (no image, just a size) to get a hit box. Set the entityType to B and set the enemy entity type to A. Then in the enemy entities check(), write the same velocity code.

2) Add an invisible tile to your mapTiles (let's say tile #15). On every update of the entity, check the tile it's sitting on by yourBackgroundMap.getTile(enemy.pos.x,enemy.pos.y) if it equals your invisible tile, then turn back.

If you can't pull it, write again.

1 decade ago by wdvretuow

I've made an entity with this code:


EntityHitbox = ig.Entity.extend({
	size: {x: 32, y: 100},
	type: ig.Entity.TYPE.B,
	checkAgainst: ig.Entity.TYPE.A,
	collides: ig.Entity.COLLIDES.FIXED


I'm thinking of a solution that might be easier. Do you maybe know a solution how to do this:

The enemy entity stand still, it doesn't moves until the player comes in a certain radius of the enemy. When the player does come close to the enemy, the enemy starts to follow the player (until the enemy is killed of course).

Is that easier to do?

1 decade ago by mdkess

One thing that might be good is to have invisible void entities, and then to set the target of your entity to these void entities. Then if the player is within range, have them attack the player (and then go back to going between void entities).

See how platforms work in the entity pack.
Page 1 of 1
« first « previous next › last »