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 jojohack

Porting over a simple tile-based game in which the player object moves from tile to tile instantly. I've accomplished this by setting the object's position directly (adding a direction-based offset) It's working well so far (with collision map and screen boundary checks) however I'm starting to see issues with entity-to-entity collision ( possibly because I'm bypassing the physics a bit )

My basic question is should I continue down this path of warping my player object around the board, or would it be better to rely on the object's velocity/acceleration (very fast movements) instead? Curious if anyone else has encountered this dilemma before.

Thanks!

1 decade ago by mLautz

Can you provide more detail on the collision issue you are seeing? And in what way are you bypassing the physics?

1 decade ago by jojohack

Sure thing. So digging into it deeper I realized that I'm not pre-emptively checking whether the new position of my player object is blocked by another entity as I move it around. For example, if I move my player object onto another tile that has a collidable object, after the update it automatically gets repositioned somewhere else ( I imagine this is the physics correcting the placement )

I suppose what I need to do is to walk the entity list beforehand to see if there are any objects occupying that tile. If so, then don't allow the movement. Earlier, I tried to correct it afterwards ( setting .pos to .last ) but that didn't seem to help ( my object disappeared instead )

1 decade ago by jojohack

If it helps, here is my current update() function.

    update: function() {
        var dx = 0;
        var dy = 0;

        if (ig.input.pressed('up')) {
            dy = -1;
        }
        else if (ig.input.pressed('down')) {
            dy = 1;
        }
        else if (ig.input.pressed('left')) {
            dx = -1;
        }
        else if (ig.input.pressed('right')) {
            dx = 1;
        }

        // check against collision map
        var result = (ig.game.collisionMap.trace(this.pos.x, this.pos.y, 
                       dx * ig.game.TILE_SIZE, dy * ig.game.TILE_SIZE,
                       ig.game.TILE_SIZE, ig.game.TILE_SIZE));

        if (!result.collision.x && !result.collision.y) {
            this.pos.x += (dx * ig.game.TILE_SIZE);
            this.pos.y += (dy * ig.game.TILE_SIZE);
        }

        // check against screen boundary
        if (this.pos.x < 0) {
            this.pos.x = 0;
        }
        else if (this.pos.y < 0) {
            this.pos.y = 0;
        }
        else if (this.pos.y >= ig.game.ROOM_H) {
            this.pos.y = ig.game.ROOM_H - ig.game.TILE_SIZE;
        }
        else if (this.pos.x >= ig.game.ROOM_W) {
            this.pos.x = ig.game.ROOM_W - ig.game.TILE_SIZE;
        }
    	
        this.parent();	
    },

1 decade ago by jojohack

Just realized that by moving the this.parent() call to the top, everything is working better now :)

1 decade ago by mLautz

I had been thinking that may help, but it seems that you already got there!
Page 1 of 1
« first « previous next › last »