Sign in to follow this  
Rafaelx

P2 Collision Group vs static sprite

Recommended Posts

Hi all, I'm trying to have my bullets group that already collides with the enemies, both of them are a group, but now that I want to add a static block or obstacle, it simply wont collide or overlap or nothing, what I want is that when the bullet collides or overlaps it gets destroyed or at least bounce into the obstacle, see code below:

////////////////My Bullets//////////These work fine and collide correctly with my enemies.//////

 createBullets: function() {
        
    this.bullets = this.game.add.group();
    this.bullets.enableBody = true;
    this.bullets.physicsBodyType = Phaser.Physics.P2JS;
    this.bullets.createMultiple(100, 'bulletSprite', 0, false);
    this.bullets.setAll('anchor.x', 0.5);
    this.bullets.setAll('anchor.y', 0.5);
    this.bullets.setAll('outOfBoundsKill', true);
    this.bullets.setAll('checkWorldBounds', true); 
        
       
    },
    
    fireBullet: function(){ 

   if (this.bulletTimer < this.game.time.time) {
            this.bulletTimer = this.game.time.time + 500;
            this.bullet = this.bullets.getFirstExists(false);
        if (this.bullet) {
            this.bullet.reset(this.tanke.x, this.tanke.y - 20);
            this.bullet.body.setCollisionGroup(this.bulletCG);
             this.bullet.body.collides([this.figuraCG]);
            this.bullet.body.velocity.y = -3500;
            }
        }

    },


//////This is the block or obstacle this just wont work no matter what I try///////////


makeOneBloque: function(){
        
        
        
        this.bloque = this.game.add.sprite(500, 950, 'Blokes');  
        
         
        this.bloque.enableBody = true;
      
        
        this.game.physics.p2.enable(this.bloque, true);
        
        this.bloque.body.kinematic = true;  
       
        
        this.bloque.body.collides(this.bullets, this.collisionBulletBloque, this); //////I tried overlaps and it just crashes the lvl
       
       
      
       
         


    },
    
      collisionBulletBloque: function(bullet) {
        
         
      
        bullet.sprite.destroy();


        
    },

 

I would greatly appreciate any help or suggestions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.