Sign in to follow this  

p2 physics with rotation

Recommended Posts

So im trying to do a space shooter based on p2 physics thrust exemple.

in the create method :

        game.physics.p2.defaultRestitution = 0.5;        

        this.bullets =; 
        this.bullets.enableBody = true;
        //this.bullets.physicsBodyType = Phaser.Physics.P2JS;
        this.bullets.createMultiple(8, 'laser');
        this.bullets.setAll('anchor.x', 0.5);
        this.bullets.setAll('anchor.y', 0.5);

Then in the update method i call this function

   fire: function () {
        if ( > this.bulletTime)
            var bullet = this.bullets.getFirstExists(false);
            var p1 = new Phaser.Point(this.ship.x, this.ship.y);
            var p2 = new Phaser.Point(this.ship.x, this.ship.y - 80);
            p2.rotate(p1.x, p1.y, this.ship.rotation, false);

            if (bullet)

                bullet.reset(p2.x, p2.y);
                bullet.lifespan = this.bulletLifespan;
                bullet.rotation = this.ship.rotation;
                this.bulletTime = + 250;


As you noticed I commented the line about settings groups physics to P2JS.

The rotation of the  laser sprite and its relative positioning to the ship is perfect but right after I uncomment the line; the laser sprite no longer rotate.

Its positionning is still relative to the ship rotation but the laser sprite stays straight (point to the top of the screen as the inital image is).

Is it suggested to choose ARCADE physics for games using rotations? Also, which property of bullet should i call to make it move on the current angle and direction?



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.