# Game.physics.arcade.intersects in Phaser 3?

**URL:** <https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590>\
**Category:** Phaser 3\
**Created:** [December 13, 2019, 4:03pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590 "2019-12-13T16:03:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kheug35](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kheug35](https://phaser.discourse.group/u/kheug35)\
**Post date:** [December 13, 2019, 4:03pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/1 "2019-12-13T16:03:20Z")

</div>

In Phaser 2  
`game.physics.arcade.intersects(body1,body2);`

How about this method in Phaser 3  
I try  
`this.physics.add.collider.intersects(body1,body2);`  
but not work , anyidea?? THX

---

<div class="post-metadata">

**Author:** ![snowbillr](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/snowbillr/32/332_2.png) [@snowbillr](https://phaser.discourse.group/u/snowbillr)\
**Post date:** [December 13, 2019, 4:21pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/2 "2019-12-13T16:21:51Z")

</div>

I think you might be looking for [https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Factory.html#overlap\_\_anchor](https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.Factory.html#overlap__anchor)

---

<div class="post-metadata">

**Author:** ![kheug35](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kheug35](https://phaser.discourse.group/u/kheug35)\
**Post date:** [December 14, 2019, 7:38am UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/3 "2019-12-14T07:38:05Z")

</div>

Thank you for reply.  
I would to covert the following project to phaser3

> **[My take on handling slopes with Phaser and ARCADE physics](https://www.emanueleferonato.com/2016/05/04/my-take-on-handling-slopes-with-phaser-and-arcade-physics/)**
>
> Who said you can't handle slopes with ARCADE physics? Look how I am doing it with Phaser

it use `game.physics.arcade.intersects` to handle when hero stand on slope.  
I try to use collider and overlap in phaser 3, but still not work, thx  
any idea

---

<div class="post-metadata">

**Author:** ![fselcukcan](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@fselcukcan](https://phaser.discourse.group/u/fselcukcan)\
**Post date:** [December 14, 2019, 8:03am UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/4 "2019-12-14T08:03:54Z")

</div>

@snowbillr is right. What you need is overlap: `overlap(object1, object2 [, collideCallback] [, processCallback] [, callbackContext])`.

But do not use it in `update`. define it in the `create`.  
Also include some playground, online demo with code, of your progress and what have you tried so we can help better.

I need a babylonjs playground like centralized playground here. Though jsfiddle is perfect. I have a [base playground here](https://jsfiddle.net/fselcukcan/bnqgy1cu/) I use for phaser questions/answers. You can fork it.

---

<div class="post-metadata">

**Author:** ![kheug35](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kheug35](https://phaser.discourse.group/u/kheug35)\
**Post date:** [December 14, 2019, 12:52pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/5 "2019-12-14T12:52:02Z")

</div>

Thanks, I upload my project to jsfiddle  
[https://jsfiddle.net/0m8rL13y/1/](https://jsfiddle.net/0m8rL13y/1/)

of download full project attachment  
[slope.zip](https://phaser.discourse.group/uploads/short-url/4OZemac7Jh8m8Nl2oppKRMQoahU.zip) (244.6 KB)

My full code thank you very much, I try to make hero stand on slope platform  
but finally not successfully…  
Full code

```
var game;
var heroSpeed = 150;
var heroGravity = 400;
var inSlope = false;
var config = {
  width: 480,
  height: 320,
  backgroundColor: 0x000000,
  scene: {
        preload: preload,
        create: create,
        update: update
    },
  physics: {
    default: "arcade",
    arcade:{
        gravity:{
          y: 400
        },
        debug: true,
        debugShowVelocity: false
    }
  }
}

window.onload = function() {
	 game = new Phaser.Game(config);
}

function preload ()
{
          this.load.spritesheet("hero", "hero.png", { frameWidth: 20, frameHeight: 32 });
          this.load.image("floor", "floor.png");
          this.load.image("slope", "slope.png");
          this.load.image("big", "big.png");
}
function create ()
{
 
          this.floor = this.physics.add.image(190, config.height - 66, "floor");
// this.floor.setOrigin(0);
          this.floor.setImmovable(true);
          this.floor.body.allowGravity = false;

          this.big = this.physics.add.sprite(config.width -100, config.height - 132, "big");
          this.big.setImmovable(true);
          this.big.body.allowGravity = false;

          this.slope = this.physics.add.sprite(config.width - 200, config.height - 132, "slope");
          this.slope.setImmovable(true);
          this.slope.body.allowGravity = false;

          this.hero = this.physics.add.sprite(32, config.height / 2, "hero");
          this.hero.setCollideWorldBounds(true);

          this.hero.goingRight = false;
          this.hero.goingLeft = false;

          this.hero.body.gravity.y = heroGravity;
          this.g = false;

       
           
          this.rightKeyPressed = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
          this.leftKeyPressed = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A); 
// https://phaser.io/examples/v3/view/input/keyboard/add-single-key
          this.rightKeyPressed.on('down', function (key, event) {
               this.hero.goingRight = true;     

          }, this);
          this.rightKeyPressed.on('up', function (key, event) {
               this.hero.goingRight = false;     
  
          }, this);
         this.leftKeyPressed.on('down', function (key, event) {
               this.hero.goingLeft = true;     
  
          }, this);
          this.leftKeyPressed.on('up', function (key, event) {
               this.hero.goingLeft = false;     

          }, this);

    
          this.physics.add.collider(this.hero, this.floor);
          this.physics.add.collider(this.hero, this.big);
          var ths = this;
          this.physics.add.overlap(this.hero, this.slope, function(b1, b2) {
        	  var dX = ths.hero.x + ths.hero.width / 2 - ths.slope.x/2;
              
          ths.hero.body.gravity.y = 0; 
          ths.hero.y = ths.slope.y + ths.slope.height - ths.hero.height / 2 - dX;
        });

     }
    
  function update ()
{

         this.hero.body.gravity.y = heroGravity;   

          if(this.hero.goingRight && !this.hero.goingLeft){
// this.hero.animations.play("walkRight", 10, true);
               this.hero.body.velocity.x = heroSpeed;
// this.hero.idleFrame = 0;     
          }
          else{
               if(!this.hero.goingRight && this.hero.goingLeft){
// this.hero.animations.play("walkLeft", 10, true);
                    this.hero.body.velocity.x = -heroSpeed;
// this.hero.idleFrame = 4;      
               }
               else{
// this.hero.frame = this.hero.idleFrame;  
                   this.hero.body.velocity.x = 0;  
                   this.hero.body.gravity.y = 0;    
               }      

     }  
  
}
```

---

<div class="post-metadata">

**Author:** ![fselcukcan](https://avatars.discourse-cdn.com/v4/letter/f/b5a626/32.png) [@fselcukcan](https://phaser.discourse.group/u/fselcukcan)\
**Post date:** [December 14, 2019, 1:05pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/6 "2019-12-14T13:05:55Z")

</div>

That is better. But I see this since the assets server you use does not allow CORS for jsfiddle at least:  
 ![Ekran Resmi 2019-12-14 ÖS 4.02.53](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/6/66290c58b6ea8baeccb8253b75cd7ceba9f9e78c.png)

Your overlap definition looks correct. You can improve it even by using the last parameter to overlap, callbackContext, `this` instead of passing it manually with an obscured name which totally correct though:

```
this.physics.add.overlap(this.hero, this.slope, function(b1, b2) {
        var dX = this.hero.x + this.hero.width / 2 - this.slope.x/2;
              
        this.hero.body.gravity.y = 0; 
        this.hero.y = this.slope.y + this.slope.height - this.hero.height / 2 - dX;
}, null, this);
```

---

<div class="post-metadata">

**Author:** ![kheug35](https://avatars.discourse-cdn.com/v4/letter/k/a5b964/32.png) [@kheug35](https://phaser.discourse.group/u/kheug35)\
**Post date:** [December 14, 2019, 1:27pm UTC](https://phaser.discourse.group/t/game-physics-arcade-intersects-in-phaser-3/4590/7 "2019-12-14T13:27:13Z")

</div>

sorry,  
Thank for your reply, i have changed it  
Please find the attached file for your full project, thank you very much  
[slope.zip](https://phaser.discourse.group/uploads/short-url/4OZemac7Jh8m8Nl2oppKRMQoahU.zip) (244.6 KB)
