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 riceje7

does anyone have any idea how i would go about implementing a secondary collision map in a level that would only effect certain entities? I am not sure if it will be best to inject into the collision map class or if i can do it through simple logic statements in my main.js.

my goal is that i can put in invisible collision tiles that enemy entities will bounce off of, change direction, and then continue on to the edge of the ground tiles then fall down onto the next level of tiles and so on an such, but my player entity will just pass through them if those specific tiles are encountered.

has anyone ever tried this before? i can't really think of how to go about starting to accomplish this any guidance would be great. thanks

1 decade ago by Joncom

For any entity that you do not want affected by the collision map, use this update method.

update: function() {

    this.last.x = this.pos.x;
    this.last.y = this.pos.y;
    this.vel.y += ig.game.gravity * ig.system.tick * this.gravityFactor;
    
    this.vel.x = this.getNewVelocity( this.vel.x, this.accel.x, this.friction.x, this.maxVel.x );
    this.vel.y = this.getNewVelocity( this.vel.y, this.accel.y, this.friction.y, this.maxVel.y );
    
    // movement & collision
    var mx = this.vel.x * ig.system.tick;
    var my = this.vel.y * ig.system.tick;
    
    /*

    // Instead of using this, which is the normal way
    // of handling collisions against the collision map
    // we will do something a little different...

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

    */

    // Create a dummy collision result,
    // which reports that there was no collision
    // (even if there really should have been).

    var res = {

        collision: {
            x: false,
            y: false
        },
        pos: {
            x: this.pos.x + vx,
            y: this.pos.y + vy
        },
        tile: {
            x: 0,
            y: 0
        }

    };

    this.handleMovementTrace( res );
    
    if( this.currentAnim ) {
        this.currentAnim.update();
    }

}

Notice how there is no this.parent();? This is very important. What we've done here is overwrite the default update method with our own which is slightly modified.
Page 1 of 1
« first « previous next › last »