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 lucastimmons

Hi there,

I am building a teleport type system based on triggers. I'd like a character to step on the teleport pad and press the up key (open). When they do I'd like the EntityPlayer entity to be removed but not killed and a new EntityPlayer spawned at the new point.

The trigger works, but the outcome is not as desired. The new EntityPlayer is created in the correct position, but the old EntityPlayer does not disappear. Is there something wrong with my remove.Entity( EntityPlayer );? Code below.

       check: function( other ) {
        // Iterate over all targets
        for( var t in this.target ) {
            var ent = ig.game.getEntityByName( this.target[t] );
                	if(ig.input.pressed('open')){
                		ig.game.removeEntity( EntityPlayer );
                		ig.game.spawnEntity( EntityPlayer, 20, 20);
                		}
        }
    }

1 decade ago by Joncom

EntityPlayer points to a class, not an instance of a class.
In other words, it is not your player.

You can make a pointer to the player like this:
var player = ig.game.getEntitiesByType(EntityPlayer)[0];

Then to remove that player, you could do this:
ig.game.removeEntity(player);

1 decade ago by lucastimmons

Thank you! That exactly fixed my issue.
Page 1 of 1
« first « previous next › last »