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!
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!