Jump to content

Problem with colllide group vs itself


Recommended Posts


I have next problem with collision..

I have a player:

 this.player = this.game.add.sprite(parseInt(playerx), parseInt(playery), 'player',5);                                                                   

    this.game.physics.arcade.enable(this.player );
    this.player.body.setSize(25, 60, 0, 5);

I have a group of animals:

 this.animal = this.game.add.physicsGroup(Phaser.Physics.ARCADE);

                   this.animal.setAll('body.immovable', true);
                      this.animal.setAll('body.bounce.x', 1);
             this.animal.setAll('body.bounce.y', 1);

then i am creating animals:


     if (zwierzenazwa == "cow"){

     this.cow =this.animal.create(zwierzex, zwierzey, 'cow');
     this.cow.frame = zwierzefrlos;
     this.cow.id = iidzwierze;
     this.cow.name = zwierzenazwa;
     this.cow.datadodaniaanim = datadodaniaanim;
     this.cow.frameleft =5;
     this.cow.frameright = 13;
     this.cow.frameup =1;
     this.cow.framedown =9;
           this.cow.body.velocity.x = 0;
    this.cow.body.velocity.y = 0; 
     //this.cow.body.immovable = true; 
    //this.cow.anchor.set(0.45, 0.4);
    if(zwierzefrlos == 5  ){
     this.cow.body.setSize(80, 38,20, 50);
     else  if(zwierzefrlos == 13) {
     this.cow.body.setSize(80, 38,30, 50);
     this.cow.body.setSize(38, 70,50, 40);
    // this.cow.body.width = 48;    
     //this.cow.body.height = 64;
    this.cow.animations.add('cowright', [12, 13, 14, 15]);
    this.cow.animations.add('cowdown', [8, 9, 10, 11]);
    this.cow.animations.add('cowup', [0, 1, 2, 3]);
    this.cow.animations.add('coweatleft', [20,20,20,20,20,20,20,20,21,22,22,23,22,22,23,22,22,23,22,22,23,22,21]);
    this.cow.animations.add('coweatdown', [24,24,24,24,24,24,24,24, 25, 26,26, 27,26,26,27,26,26,27,26,26,27,26,25,24]);
    this.cow.animations.add('coweatright', [28,28,28,28,28,28,28, 29, 30, 31,30,30,31,30,30,31,30,30,31,30,30,31,30,30,31,30,30,29,28]);
    this.cow.animations.add('coweatup', [16,16,16,16,16,16,16, 17, 18, 19,18,18,19,18,18,19,18,18,19,18,18,19,18,18,19,18,17]);    



Then collision:

    this.game.physics.arcade.collide(this.player, this.animal, this.stopanimplayer, null, this); 
    this.game.physics.arcade.collide(this.animal, this.animal, this.stopanimzwierz, null, this);  


And i have a problem because i must set immovable true to all animals to collide with player, but then there dont collide with each other in group.. Anyone can help to set it work?


Link to comment
Share on other sites

I don't use Phaser, so I don't know if this is possible, but one hack idea is to try the 1 vs. 999 mass thing again (from above), but hook into some post-collision callback that always updates the animal velocity to what is was before the velocity exchange (which seem to happen in Phaser's separateX and separateY methods).

For example, if you have a pre-collision callback opportunity, you can save `animal._prevVelocity` that is used after the animal velocity mutation to reset the animal velocity if it collides with a player. Yet animal↔animal collisions will still work.

Also, anyone trying to make their moving platforms collide will each other will encounter this issue, so maybe "moving platform" search terms can help you find other people dealing with this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...