Jump to content

Player goes through a platform when he's not supposed to. p2 issue


kriket
 Share

Recommended Posts

I have implemented a see-saw but at the edges the player can go right through it if he stays at the edges for more than a few seconds. 

Check it out here. http://seesaw.site44.com/

Move player = click on left side of game to move left and vice-versa for right side. Click in middle to jump.


  create: function() {    this.game.physics.p2.setImpactEvents(true);    this.game.physics.p2.restitution = 0.5;    this.game.physics.p2.gravity.y = 300;    this.playerCollisionGroup = this.game.physics.p2.createCollisionGroup();    this.logCollisionGroup = this.game.physics.p2.createCollisionGroup();          this.player = this.game.add.sprite(this.game.width/2, this.game.height/4, 'player', 'front.png');        // SEE-SAW    this.logs = this.game.add.group();    this.logs.enableBody = true;    this.logs.physicsBodyType = Phaser.Physics.P2JS;          this.logs.create(400, 450, 'log');    for(var i = 0; i < this.logs.children.length; i++){            //           this.logs.children[i].body.kinematic = true;            this.logs.children[i].body.dynamic = true;            this.logs.children[i].body.data.gravityScale = 0;            //            this.logs.children[i].body.setZeroVelocity();            this.logs.children[i].body.setCollisionGroup(this.logCollisionGroup);            this.logs.children[i].body.collides(this.playerCollisionGroup);     }            this.player.smoothed = false;    this.game.physics.p2.enable(this.player);    this.player.body.dynamic = true;    this.player.body.setCollisionGroup(this.playerCollisionGroup);          this.player.body.collides(this.logCollisionGroup);    this.player.body.gravity.y = 0;    this.player.body.fixedRotation = true;    this.game.physics.p2.updateBoundsCollisionGroup();    this.game.renderer.renderSession.roundPixels = true;    this.yAxis = p2.vec2.fromValues(0, 1);        },    update: function() {    for (var i = 0; i < this.logs.children.length; i++) {        this.logs.children[i].body.setZeroVelocity();        if(this.logs.children[i].body.x != 400){              this.logs.children[i].body.x = 400;        }        if (this.logs.children[i].body.y != 450){              this.logs.children[i].body.y = 450;         }        if(this.logs.children[i].body.rotation > 0.4){            //            this.logs.children[i].body.setZeroRotation();            this.logs.children[i].body.rotation = 0.4;        }        if (this.logs.children[i].body.rotation < -0.4){            //           this.logs.children[i].body.setZeroRotation();            this.logs.children[i].body.rotation = -0.4;       }    }};
Link to comment
Share on other sites

Does it also do that if you removed the fixed rotation on the player? What are you trying to do in the update loop? Rotate the log? Why don't you use a revolute constraint? http://phaser.io/examples/v2/p2-physics/revolute-constraint

 

Hi tips. How are you.

 

Basically, I am trying to imitate a real-world see-saw where u get on one end and u try to balance and not fall off. Its a platform in a platformer game. Just a see-saw. Thats what I am trying to achieve in update loop and otherwise. 

I m not using revolute constraint cos that only allows two bodies to rotate relative to each other around a point. I am not after this. I was just after a basic physics see-saw, which didnt transtate but rotated based on where the player was on it (upto a point, say 40 degress either way so as not to rotate completely. Again, just a real world see-saw).

 

It still does it if I remove fixed rotation on player.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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