# Sprite Collision from top only

**URL:** <https://phaser.discourse.group/t/sprite-collision-from-top-only/10362>\
**Category:** Phaser 3\
**Created:** [October 4, 2021, 3:28pm UTC](https://phaser.discourse.group/t/sprite-collision-from-top-only/10362 "2021-10-04T15:28:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcticnerd](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@arcticnerd](https://phaser.discourse.group/u/arcticnerd)\
**Post date:** [October 4, 2021, 3:28pm UTC](https://phaser.discourse.group/t/sprite-collision-from-top-only/10362/1 "2021-10-04T15:28:10Z")

</div>

I’m new to phaser and just trying to figure out how I can modify a collider to allow sprites to collide from one direction but not others.

I have a player sprite and a platform sprite. Currently they collide normally, the player can’t pass through the platform in any direction. What I would like is for the the player to collide with the platform when they are coming down onto it. Not when they are jumping up through it.

Looking through the documentation I see that tiles have different collide members such as collideUp which could accomplish what I want but I want my platforms to be sprites not tiles so I can animate them.

I set up a collider callback between my player sprite and my platform sprite group but I don’t know how I can dynamically change the collision behavior. Any thoughts would be apricated.

create() {  
…  
this.platformGroup = this.physics.add.group();  
this.platformGroup.defaults.setAllowGravity = false;  
this.platformGroup.defaults.setImmovable = true;

this.player = new Player(this, spawnPoint.x, spawnPoint.y);

this.physics.add.collider(this.player.sprite, this.platformGroup, this.handlePlayerPlatformCollision, undefined, this);  
…  
}

private handlePlayerPlatformCollision(obj1: Phaser.GameObjects.GameObject, obj2: Phaser.GameObjects.GameObject)

{  
// Some kind of logic to turn on and off collision  
}

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [October 4, 2021, 4:37pm UTC](https://phaser.discourse.group/t/sprite-collision-from-top-only/10362/2 "2021-10-04T16:37:32Z")

</div>

👋

One way is

```javascript
platform.body.checkCollision.down = false;

```

Another is

```javascript
// Pass as `processCallback` in `this.physics.add.collider()`
function processPlayerPlatformCollision
(
  player: Phaser.Types.Physics.Arcade.GameObjectWithBody,
  platform: Phaser.Types.Physics.Arcade.GameObjectWithBody
)
{
  return (player.body.velocity.y > 0);
}

```

---

<div class="post-metadata">

**Author:** ![arcticnerd](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@arcticnerd](https://phaser.discourse.group/u/arcticnerd)\
**Post date:** [October 5, 2021, 1:28am UTC](https://phaser.discourse.group/t/sprite-collision-from-top-only/10362/3 "2021-10-05T01:28:31Z")

</div>

> [@samme](#):
>
> `platform.body.checkCollision.down = false;`

Great, thanks for the help. This worked exactly like I wanted. I didn’t even see that property in the body.
