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

10 years ago by Nozferatu

Hi I'm pretty new to Impact, I thought I would start off with something simple - player movement.

I had the opportuntity to look at http://impactjs.com/forums/code/top-down-rpg-style-tile-based-grid-movement which is really close to what I want, but I don't really want to be restricted to moving only up, down, left, or right. I would like to be able to move diagonally, a la, pressing up and left at the same time. Similar to http://www.cross-code.com/en/play

I peiced together some very basic movement for my Player entity:

if( ig.input.state('up') ) {
    this.vel.y = -this.speed;
}
else if( ig.input.state('down') ) {
    this.vel.y = this.speed;
}
if( ig.input.state('left') ) {
    this.vel.x = -this.speed;
}
else if( ig.input.state('right') ) {
    this.vel.x = this.speed;  
}

So with this I have the right movement range, but the only issue is that the player keeps going, there's nothing in place to tell it "Hey, you reached your destination time to stop moving". I considered getting around this entirely and just moving the entity directly via the pos attribute, but it seems that prevents the collision detection from working.

What's the best approach for something like this?

10 years ago by Nozferatu

Geh, face-palming really hard right now. Realized what was wrong literally seconds after posting my question. This does what I need.

if( ig.input.state('up') ) {
    this.vel.y = -this.speed;
}
else if( ig.input.state('down') ) {
    this.vel.y = this.speed;
}
else if( ig.input.state('left') ) {
    this.vel.x = -this.speed;
}
else if( ig.input.state('right') ) {
    this.vel.x = this.speed;  
}
else
{
    this.vel.x = 0;
    this.vel.y = 0;
}
Page 1 of 1
« first « previous next › last »