Jump to content

Check end of overlap/collision


Taggrin
 Share

Recommended Posts

Hi everyone,

 

I am looking for a way to check the end of an overlap. I've been looking for quite some time without success, so I hope any of you can help me.

 

Basic summary of the game: space shooter where you can go to planets to buy / restock items. There is an oxygen bar slowly ticking down, but I want it to stop ticking down while being docked at a planet.

 

What I have so far is (important parts cut out):

//In createship.docked = false;//In updatethis.physics.arcade.overlap(ship,planets,this.docking,null,this);//Reduce oxygen over timethis.oxygenTick();//Collision handler docking: function (ship,planets) {    ship.docked = true; }, //Oxygen ticksoxygenTick: function () {    //One tick of oxygen every 2 seconds    if (ship.docked == false){       if (this.time.now > oxygenTime){         ship.oxygen -= 1;         oxygenBar.scale.x = (ship.oxygen / ship.oxygenmax);         oxygenTime = this.time.now + 2000;       }    }},

So pretty much what happens now is that as soon as I "dock" at a planet, the oxygen stops ticking down. However, this will stay permanent, even after leaving the planet. I want to check that the ship is NOT overlapping any planet (group) anymore to set ship.docked back to false. Anyone knows a way to do this?

 

Thanks in advance :).

Link to comment
Share on other sites

 

Hello,

 

how about just putting ship.docked = false; into update loop as well?

// updateship.docked = false;collisionticks

 

That works, thank you very much! Sometimes the easy solutions are overlooked hehe. 

 

I first thought it might would give some issues as it basically is constantly flipping false/true in the update function when docked, but since the oxygen ticks are after the collision detection this indeed does the job.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...