# If(collide and create.sprite)

**URL:** <https://phaser.discourse.group/t/if-collide-and-create-sprite/7484>\
**Category:** Phaser 3\
**Created:** [September 23, 2020, 12:36pm UTC](https://phaser.discourse.group/t/if-collide-and-create-sprite/7484 "2020-09-23T12:36:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ytarikulker35TR](https://avatars.discourse-cdn.com/v4/letter/y/b38774/32.png) [@ytarikulker35TR](https://phaser.discourse.group/u/ytarikulker35TR)\
**Post date:** [September 23, 2020, 12:36pm UTC](https://phaser.discourse.group/t/if-collide-and-create-sprite/7484/1 "2020-09-23T12:36:20Z")

</div>

hi hello there is a character in my game when it touches an object it turns into character 2. With the “if” I want to check if the character is 2, does it touch the object? I want him to check.  
`if (this.characters = this.physics.add.sprite (game.config.width / 4 * 1, game.config.height / 8 * 4," dropluCharacter ") && this.physics.world.collide (this. character, this.dusmanGroup, function () {}, null, this)) {}`  
I tried the command and there was an error.  
`Error: TypeError: Cannot read property 'velocity' of undefined at playGame. <anonymous>`  
Please help IMMEDIATELY. THANKS NOW!

---

<div class="post-metadata">

**Author:** ![Santette](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Santette](https://phaser.discourse.group/u/Santette)\
**Post date:** [September 23, 2020, 5:26pm UTC](https://phaser.discourse.group/t/if-collide-and-create-sprite/7484/2 "2020-09-23T17:26:39Z")

</div>

Not sure if it’s what you need, i’ll need some more details but:

```
let rectGroup;

class Scene1 extends Phaser.Scene {

    constructor() {
        super('Scene1');
    }

    create(){
        rectGroup = this.add.group();

        // Replace this with your "collision listener" function
        this.physics.world.on('worldbounds', ()=>{
            let r = this.add.rectangle(0, 0, 80, 80, 0x6666ff).setOrigin(0);
            this.physics.add.existing(r);
            rectGroup.add(r);
            addPhisycs(r);
        });
    }
}

function addPhisycs(r) {
    r.body.setVelocity(100, 200)
    .setBounce(1, 1)
    .setCollideWorldBounds(true);
    r.body.onWorldBounds = true;
}
```
