1 decade ago
by Jon123
I'm trying to create patrolling enemies like in the Mario games, but can;t figure out how to get the entity to turn around after a certain distance, moving forward and back on itself.
Any ideas? Thanks
1 decade ago
by Joncom
Rather than a certain distance, it might be easier to think of it as "after a certain amount of time"... Create a timer
var timer = new ig.Timer();
and change directions after a certain amount of time has elapsed...
// Change direction after 5 seconds...
if(timer.delta() >= 5) { changeDirection(); }
1 decade ago
by Jon123
Ah right, makes sense thanks. I am guessing "changeDirection();" is a method I would have to implement? It isn't a standard method with ImpactJS is it?
1 decade ago
by Jon123
Do you know if there is a way to check whether the entity has either hit a wall or come to the edge of a platform, and then turn around?
1 decade ago
by stillen
Theres a lot of simple good instructions in this project:
https://github.com/gamecook/super-jetroid-starter-kit
Also the two books that are featured on the site have a lot of good information and supporting the authors keeps them helping out the community.
handleMovementTrace: function (res) {
this.parent(res);
// collision with a wall? return!
if (res.collision.x) {
this.flip = !this.flip;
}
}
1 decade ago
by Jon123
@stillen, that's amazing! Thanks a lot, hopefully I can take the relevant code from that to get my game working.
1 decade ago
by Jon123
@joncom, thanks for the timer idea too, I can use that for ground entities.
Page 1 of 1
« first
« previous
next ›
last »