# How can I not bounce on the item I am collecting?

**URL:** <https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718>\
**Category:** Phaser 3\
**Created:** [June 3, 2021, 9:13am UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718 "2021-06-03T09:13:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rah-emil](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rah-emil/32/5238_2.png) [@rah-emil](https://phaser.discourse.group/u/rah-emil)\
**Post date:** [June 3, 2021, 9:13am UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/1 "2021-06-03T09:13:33Z")

</div>

Ball class:

```javascript
import { addBounceTween } from './../helpers'

export default class Ball extends Phaser.Physics.Arcade.Sprite
{
	/**
	* @param {Phaser.Scene} scene
	* @param {number} x
	* @param {number} y
	* @param {string} texture
	*/
	constructor(scene, x, y, texture)
	{
		super(scene, x, y, texture)
		this.setScale(1.4)
		addBounceTween.call(scene, this)
	}
}

```

My ball:

```javascript
this.balls = this.physics.add.staticGroup({classType: Ball, allowGravity: false, immovable: true })
this.balls.create(1420, 773, 'ball')

```

My player:

```javascript
this.player = this.physics.add.sprite(100, 600, 'player')

```

My collider:

```javascript
this.physics.add.collider(this.player, this.balls, this.handleCollectBall, undefined, this)

```

I can touch the top of the ball, but that shouldn’t be.

---

<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:** [June 3, 2021, 3:10pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/2 "2021-06-03T15:10:28Z")

</div>

> [@rah-emil](#):
>
> My collider:
> 
> ```javascript
> this.physics.add.collider(this.player, this.balls, this.handleCollectBall, undefined, this)
> 
> ```

Use `add.overlap(…)` instead.

---

<div class="post-metadata">

**Author:** ![rah-emil](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rah-emil/32/5238_2.png) [@rah-emil](https://phaser.discourse.group/u/rah-emil)\
**Post date:** [June 3, 2021, 3:30pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/3 "2021-06-03T15:30:52Z")

</div>

It doesn’t help me. In this case, I can jump by simply touching the element …

---

<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:** [June 3, 2021, 3:45pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/4 "2021-06-03T15:45:15Z")

</div>

Show your jump code?

Probably avoid using `body.touching.down`.

---

<div class="post-metadata">

**Author:** ![rah-emil](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rah-emil/32/5238_2.png) [@rah-emil](https://phaser.discourse.group/u/rah-emil)\
**Post date:** [June 4, 2021, 10:26am UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/5 "2021-06-04T10:26:05Z")

</div>

Player jump:

```javascript
this.player.setVelocityY(-450)

```

---

<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:** [June 4, 2021, 4:27pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/6 "2021-06-04T16:27:21Z")

</div>

I don’t understand the problem.

What is happening now? What do you want to happen instead?

Can you post the whole scene code?

---

<div class="post-metadata">

**Author:** ![rah-emil](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rah-emil/32/5238_2.png) [@rah-emil](https://phaser.discourse.group/u/rah-emil)\
**Post date:** [June 5, 2021, 4:59am UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/7 "2021-06-05T04:59:12Z")

</div>

> **[IMG\_7044.MP4](https://disk.yandex.ru/i/cKe8wq_ensXtYw)**
>
> Посмотреть и скачать с Яндекс.Диска

Main game:

```javascript
import Ball from './../../game/Ball'

preload(){
	this.load.image('ball', 'assets/ball.png')
	this.load.spritesheet(`player`, `assets/player/player.png`, { frameWidth: 79, frameHeight: 233})
}

create(){
	this.balls = this.physics.add.group({classType: Ball, allowGravity: false, immovable: true})
	this.balls.create(1420, 773, 'ball')
	this.balls.create(1680, 743, 'ball')
	this.balls.create(2280, 773, 'ball')
	this.balls.create(2700, 743, 'ball')

	this.player = this.physics.add.sprite(100, 600, `player`)
	this.player.setBodySize(79, 233)
	this.player.setOffset(0, 0)

	this.physics.add.collider(this.player, this.balls, this.handleCollectBall, undefined, this)
}

update(){
	
}

handleCollectBall(player, ball) {
	ball.destroy()
}

```

Ball class:

```javascript
export default class Ball extends Phaser.Physics.Arcade.Sprite
{
	/**
	* @param {Phaser.Scene} scene
	* @param {number} x
	* @param {number} y
	* @param {string} texture
	*/
	constructor(scene, x, y, texture)
	{
		super(scene, x, y, texture)
		this.setScale(1.4)
		addBounceTween.call(scene, this)
	}
}

export function addBounceTween(object) {
    return this.tweens.add({
        targets: object,
        duration: 800,
        y: '-=8',
        yoyo: true,
        repeat: -1,
        ease: 'Sine.easeInOut'
    })
}

```

---

<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:** [June 5, 2021, 4:02pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/8 "2021-06-05T16:02:50Z")

</div>

What about code for player movement?

---

<div class="post-metadata">

**Author:** ![rah-emil](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rah-emil/32/5238_2.png) [@rah-emil](https://phaser.discourse.group/u/rah-emil)\
**Post date:** [June 7, 2021, 2:26pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/9 "2021-06-07T14:26:16Z")

</div>

I check if it is still on the ground with:

```javascript
this.player.body.touching.down

```

---

<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:** [June 7, 2021, 5:11pm UTC](https://phaser.discourse.group/t/how-can-i-not-bounce-on-the-item-i-am-collecting/9718/10 "2021-06-07T17:11:06Z")

</div>

Use `body.blocked.down` or `body.onFloor()` instead.
