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 Cadence96

Hi, I have Player and Coin entities. Both entities have a check method because I want to add a different condition for each.

Check in Coin works as expected when the Player touches it.
Check in Player doesn't do anything when the Player touches the Coin.

What can I do to make check method work in Player?

Here are the important parts of the code of both entities
Player Entity:
EntityPlayer = ig.Entity.extend({
        type: ig.Entity.TYPE.A, 
        checkAgainst: ig.Entity.TYPE.NONE,
        collides: ig.Entity.COLLIDES.PASSIVE,
        // init, update, etc
        check: function(other) {
            if (other instanceof EntityCoin) {
                console.log('EntityPlayer touched EntityCoin');   
            }
        },


Coin Entity:
EntityCoin = ig.Entity.extend({
	type: ig.Entity.TYPE.NONE,
	checkAgainst: ig.Entity.TYPE.A,
	collides: ig.Entity.COLLIDES.NEVER,
        // init, update, etc
        check: function(other) {
            if (other instanceof EntityPlayer) {
                console.log('EntityCoin has been touched by EntityPlayer');
            }
        }

1 decade ago by mglnunez

ig.Entity.TYPE.NONE

Does not mean that there is a type of "none" assigned, but there is no type assigned.
So your player is not checking against anything.
You would need to assign the coin to be either type A or B and have the player check against that type.

1 decade ago by Cadence96

Thanks mglnunez. With your answer I solved the problem but there were another one.

In my example I didn't include I was killing EntityCoin, it was also preventing the check execution from EntityPlayer.
Page 1 of 1
« first « previous next › last »