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 sleenee

Ok I have been looking at this and I thought it should work but I'm missing something I guess.

I modified the handleMovementTrace in the non-playable entity in order to make him stop for walls but it's not working out.

	    handleMovementTrace: function(res) {
            
	    	this.parent(res);
            // collision with a wall? stop!
            if (res.collision.x && this.vel.x > 0) {
               this.vel.x = 0;
               this.movementtimer = new ig.Timer();
            }
            if (res.collision.y && this.vel.y > 0) {
               this.vel.y = 0;
               this.movementtimer = new ig.Timer();
            }
          
        },

the movementtimer is something I put in there to make him change direction. Every 5 seconds he needs to reconsider wether he wants to change direction and the timer resets every time he stands still. However, he never stands still since the handlemovementtrace is not working in my case.

I buy a beer to the one who solves it, I've been looking at it for hours, tried a lot of stuff and now I'm frustrated and will go drawn my brain in alcohol in order to forget about it.

thanks in advance,

Sleenee

1 decade ago by Hareesun

handleMovementTrace: function(res) {
  // collision with a wall? stop!
  if (res.collision.x && this.vel.x > 0 || res.collision.x && this.vel.x < 0) {
    // if this hits a wall and it’s vel.x is below or above 0 stop.
    this.vel.x = 0;
    this.movementtimer = new ig.Timer();
  }
  if (res.collision.y && this.vel.y > 0 || res.collision.y && this.vel.y < 0) {
    this.vel.y = 0;
    this.movementtimer = new ig.Timer();
  }
  this.parent(res);
},

Possibly? There is of course the Y problem that if it’s on the ground, it won’t move at all. So strip that and test. :)

1 decade ago by sleenee

Ok now I'm back after a long night of drinking and...stuff. I'm going back to this fun issue. Thanks for the reply Hareesun but I'm afraid it doesn't really solve my problem. The NPC just keeps on walking against the walls and my furniture (damn him). Btw it is a top down view so there is no standing and jumping involved, he can walk in 4 directions.

I am going back to finding a way to avoid letting my NPC hit walls. In the meantime if anyone feels like posting a solution or a way he/she does this him/herself, be my guest, the promise of beer still stands for the one who solves it.

thank you people,

Sleenee

1 decade ago by BlackDolphinMedia

there are 4 different types of collitions .. the easyest way would be if the npc walks a predefined way > with void triggers .. if that dosent work you could always give a collision.fixed

1 decade ago by Hareesun

Wait. You mean the animation still plays? Because technically as soon as an entity hits a wall its velocity is 0. Even if it has a constant velocity. If the entity is walking through walls, you’ve not got this.parent(); on the update function or something.

Just rewrite how the animation plays. So it’s something like…
if(this.vel.x > 0 || this.vel.x < 0) {
  // walking animation here
} else if (this.vel.x == 0) {
  // idle animtion here
}

I can pull some more advanced animation control code if you’d rather, I’m just being lazy. :P

1 decade ago by sleenee

@BlackDolphinMedia
Hmm, letting them walk a predefined way would be a solution however I am going to make the game in such a way that the entities are spawned randomly on reload on open spaces (still have to find out how to do that though) so their starting points will be random too and predefining a path then looks like more trouble than going for the "stopping at walls"-solution.

@Hareesun
For the animation, that is ok. If the character's velocity is 0 it will stop walking but I can't tell it to stop walking when it reaches a collision point. However the weird thing is that sometimes he does do it right, he just doesn't always stop when he should. As if in some cases he just could not detect the collision and assumes a free path.

Could I have these problems because my collision tiles are way smaller than my other tiles? Or would this not affect the movementtrace? I need them to be smaller so I can make the entities both walk in front and behind an object (tree for example).
Page 1 of 1
« first « previous next › last »