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 daitoshokan

EDIT: This topic has been resolved. For details, see this topic.
http://impactjs.com/forums/help/check-if-two-entities-stopped-colliding

I am trying to accomplish an effect that if the player entity is standing in front of a computer entity, he can hit a button to use it. In effect I need this button to have no effect if the sprites are not overlapping, and and to run some code if they are.

I've been going about this by checking for a collision event between the two entities, and toggling a boolean flag that can be used in a button press conditional statement. This is good, I can initialize the property to false, and then have it toggle to true when the sprites begin overlapping. But now I don't know how to toggle it back to false! I tried to make that happen in the player entity's update function, but then it never toggles to true.

Here is my code as it is written now:
In the check of the "terminal" that the player needs to be able to do stuff at, I have
check: function( other ) {
//console.log("Press my buttons!");
// other.atTerminal=true;
}
Works to turn the flag to true once, but it will never turn itself back off. Another angle I'm trying is having the function in the player.js file:

if( other instanceOf EntityTerminal ) {
atTerminal = true;
console.log("Press my buttons!");
}

Although a knowledgable guy on this forum posted that code and I adapted it to my purposes, the error console is indicating that it doesn't recognize the identifier "instanceOf". And even if this did work, I would not know how to toggle it back to false once away from the terminal. Is there a better way? Or a way to make mine work? Thanks!

1 decade ago by daitoshokan

Update: I worked a bit on the player-side implementation, and came up with this function:

check: function(other){

if( other instanceof EntityTerminal ) {
this.atTerminal = true;
console.log("Press my buttons!");
}

},

My problem was that instanceof is all lower case, and I was putting it in the wrong check function (a sub-class of player, instead of creating a new override for player). So now as far as doing this check in the player class or the terminal class, it doesn't matter. I just need to know how to toggle back to false with this implementation, if possible.
Page 1 of 1
« first « previous next › last »