Jump to content

P2 physics speed up sprite (pinball flipper collision)


streamer
 Share

Recommended Posts

Hi,
I'm newbie in Phaser (excuse my english)... 
 
Currently I'm developing pinball game. I have created flippers (paddle) via revolute constraints and ball in P2 physics... Everything works perfect but I need to make flippers more powerfull when they hit to ball (I need ball acceleration)... currently

CreatePaddle = function(game,x,y, side) {    Phaser.Group.call(this, game);    this.side = side;    this.flipped = false;    this.sprite_two = game.add.sprite(x, y, 'paddle');    game.physics.p2.enable(this.sprite_two, true);    //this.sprite_two.body.clearShapes();    if(side == 'right') {        this.sprite_two.body.loadPolygon('physicsData', 'paddle2');        this.maxAngle = 30;        this.pivotOffsetX = 50;        this.sprite_two.scale.x *= -1;        this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y);        this.pivotOffsetX = 50;    } else {        this.sprite_two.body.loadPolygon('physicsData', 'paddle');        this.maxAngle = -30;        this.pivotOffsetX = -50;        this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y);    }    this.game.physics.p2.enable(this.pivotPoint);    this.pivotPoint.body.static = true;    this.pivotPoint.body.clearCollision(true,true);    this.flipperConstraint = this.game.physics.p2.createRevoluteConstraint(this.sprite_two, [this.pivotOffsetX, 0], this.pivotPoint, [0, 5]);    this.flipperConstraint.upperLimitEnabled = true;    this.flipperConstraint.lowerLimitEnabled = true;    return this.flipperConstraint;}

Ball is created like this:

//ball - circlecircle = game.add.sprite(470, 300, 'circle');circle.anchor.setTo(0.5, 0.5);game.physics.p2.enable(circle, false);circle.body.setCircle(16);circle.body.fixedRotation = true;

Flippers are loaded like this:

this.paddle1 = new CreatePaddle(game, 270, 2390, 'left');this.paddle2 = new CreatePaddle(game, 460, 2390, 'right');

But how can I add more power to ball which collide with my flipper (paddle) ? 

Should I create custom material for flipper or is there easier way?

 

Thanks for answers.

Link to comment
Share on other sites

I think the easist way is:

paddle.body.onBeginContact.add(paddleHit, this);paddleHit=function(_obj){    if(_obj.name=="ball"){        if(_obj.velocity.y<0){            if(paddle.isDeployed){                _obj.velocity.y*=3;            }        }    }}

Edit: Actually, this will not work perfectly since if you let the ball ball on the paddle and the you depploy them, it will not be fired.

Link to comment
Share on other sites

I think the easist way is:

paddle.body.onBeginContact.add(paddleHit, this);paddleHit=function(_obj){    if(_obj.name=="ball"){        if(_obj.velocity.y<0){            if(paddle.isDeployed){                _obj.velocity.y*=3;            }        }    }}

Edit: Actually, this will not work perfectly since if you let the ball ball on the paddle and the you depploy them, it will not be fired.

 

Yes, its not very good... its closer to what I want but better will be it this is applied when ball leaving  paddle area

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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