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 sgrieger

I have a side scroller where I can fly a small plane. I can go up, down and I can backtrack (right) a little bit. I can loop-d-loop too.

I am now trying to get the enemy plane to follow my little plane.

So as I go up, it needs to match my altitude and the same as I descend.

If I loop-d-loop, the enemy plane needs to follow me around also doing a loop but always behind me.

I'm having a little difficulty with the logic of how to do the loop-d-loop follow me.

Any help on visualising the logic required would be a huge help.

1 decade ago by dominic

As I understand it, the position of the enemy plane is the same position as your own, but shifted to the left. So something like this should work:

// in your enemy's entity
update: function() {
	// get the player entity
	var player = ig.game.getEntityByName('player');

	this.pos.x = player.pos.x - 100; // shifted 100 pixels to the left
	this.pos.y = player.pos.y;

	this.parent();
}

1 decade ago by lazer

Dominic, I may have misunderstood his question but I thought that his main issue was the loop-d-loop follow (I'm picturing a loop-d-loop as the player going down and back up in a circle). From what I understand he wants the enemy to also do a loop-d-loop, which would mean that depending on distance it would have to actually be above the player instead of just offset to the left (so flying in an arc behind the player's arc).

Or I could be completely wrong. Sgrieger, can you post a screenshot or basic sketch of the kind of thing you have now/are trying to achieve?

1 decade ago by y0ungb0b

Yeah, sounds like he wants an entity to follow behind another entity, kind of like the 'option' drones in Gradius etc. that mimic the players movement path.

Ive had a quick stab at this before. Unfortunately I can't find my code and I remember it didn't work that well either.

Anyway, I don't know if theres an elegant way to do it but I 'recorded' the movements of my player entity into a array and the following entity just read the movement data oldest to newest. You need to make the array larger depending on how far away the following entity is from the player entity or the last following entity if you had a chain of them.

Sorry I can't be of much more help. If any ninja coders here know how to achieve the effect better, Id like to know myself! :)
Page 1 of 1
« first « previous next › last »