Sign in to follow this  

help - arcade physics with p2 objects

Recommended Posts

Quote: "physic arcade with objects that have physic p2."   sorry.. to me that sounded like you want to combine arcade and p2 physics..


so you want to know how to set something up in p2 that formerly worked in arcade...


i think you'll have to post more code... or even provide a link to the testcase :)

Share this post

Link to post
Share on other sites

Piece of my code :)


            this.player =, 50, 'player');
  , true);
            this.player.body.setRectangle(33, 78);
            this.snakes =;
            this.snakes.create(900, 80, 'snake');
            this.snakes.forEach(enemy.setupSnake, this);


           this.snakes.forEach(enemy.moveSnake, this);




//aux functions

            enemy.setupSnake = function(snake) {
                snake.body.setRectangle(30, 45);
       = 2;
            enemy.moveSnake = function(snake) {
        , this.player, utils.rangeRandom(90, 100), utils.rangeRandom(120, 130));

Share this post

Link to post
Share on other sites

so you ARE trying to combine p2 with arcade ... thats what i meant..  AFAIK you can not use arcade stuff on p2 bodies..


but have a look here:


i found your problem interesting and tried to solve it.. i think i found a way to do what you want with p2..  but it's very complicated ^^

i do not fully understand it myself as i just combined different approaches i saw in one of rich's lab examples... 


have a look at this function i wrote:


function moveBullets (bullet) {     var dx = ship.body.x - bullet.x;    var dy = ship.body.y - bullet.y;    bulletRotation= Math.atan2(dy, dx);    bullet.body.rotation = bulletRotation + game.math.degToRad(-90);    var angle = bullet.body.rotation + (Math.PI / 2);    bullet.body.velocity.x = 50 * Math.cos(angle);    bullet.body.velocity.y = 50 * Math.sin(angle);}

it rotates the bullets to the "ship" object and then sets x and y velocity according to the angle..  


you need to call this function on every bullet (or snake) in the update loop (and "ship" needs to be a global)


Share this post

Link to post
Share on other sites

p2 is very new... it just got introduced to phaser with 2.0 a few days ago..  while arcade physics was there from the beginning.. 


i guess rich will make sure that p2 will have the same useful and easy to use functions when he finds the time to implement them..


let's just wait and see :)

Share this post

Link to post
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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.