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 Joncom

In the update function of my player.js entity I have the following code:

var res = ig.game.collisionMap.trace( this.pos.x, this.pos.y, this.pos.x+16, this.pos.y+16, 4, 4 );
if ( res.collision.x || res.collision.y )
{
    this.messagebox = "Collision found........\n" +
		      "\n player is @:\n " + this.pos.x + "," + this.pos.y +
		      "\n collision:\n " + res.pos.x + "," + res.pos.y;
}

Here's an example output of messagebox:

Collision found........
player is @:
224,192
collision:
464,255


It's weird because I'm standing in the middle of an open grassy field in the game. How is it possible that I can be detecting collisions nearby when I'm not near any?

1 decade ago by quidmonkey

The third and fourth parameters of .trace() should only be 16 - the size of your Entity. Right now the size.x = 224 + 16 and size.y = 192 +16. So essentially, your Entity is freaking huge.

1 decade ago by Joncom

Basically what I'd like to do is this: check if the area directly left (ie. the pixel literally beside the player) is walkable.

Here is my attempt:

var res = ig.game.collisionMap.trace( this.pos.x-1, this.pos.y, 1, 1, this.size.x, this.size.y );

Oddly enough, it only picks up collisions when I'm directly left of a the collision piece.

1 decade ago by quidmonkey

Oops, my bad. The signature for collisionMap.trace() is this:

trace: function( x, y, vx, vy, objectWidth, objectHeight )

Thus, the 3rd and 4th parameters were not size, but vel.

Previously, your 3rd and 4th parameters were too large, as your entity was moving an immense distance in a single frame. This time, your vel.x = 1, which means your Entity is moving towards the right; so yes, it&039;ll only pick up collisions when your Entity is to the left of the collision tile. If you change it so that #vel.x = -1, your Entity will be moving towards the left, and it'll only pick up collisions when your Entity is to the right of the collision tile.

1 decade ago by Joncom

My god.

vx and vy are velocities...

I was thinking they were a second x and y value such as to create two points to form a rectangle... No wonder I was having a nightmare of a time.

Thanks quid!
Page 1 of 1
« first « previous next › last »